question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Tabs] Tabs get mounted when they are inactive

See original GitHub issue

Hi there! First of all I would like to thank you for this fantastic library. It’s really impressive!

Expected Behavior

The Tabs component only mounts the contents of a TabPanel to the DOM when the tab is activated/clicked/selected.

Link to minimal reproduction https://codesandbox.io/s/chakra-tabs-mounting-early-kcign

Steps to Reproduce

  1. Open the codesandbox
  2. Open the console view
  3. See console logs from both tabs, although we only ever activated the first one

Suggested solution(s)

Instead of using display: none to hide the DOM elements, there should also be an option to not mount the DOM elements at all until the tab is activated.

Desktop (please complete the following information):

  • OS: MacOS 10.15.5
  • Browser: Chromium
  • Version: 84.0.4132.0

Additional context

I’m currently using the Tabs component in an application where every tab fetches a lot of data. The fact that the Tabs component renders all tabs to the DOM and thereby fires lots of HTTP requests simultaneously is causing performance issues. I have tried to use the isManual option, but the tabs still get rendered to the DOM.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
dmitrucommented, Jul 25, 2020

This issue is similar in spirit to this other one with Menu and Popovers rendering their content while closed: https://github.com/chakra-ui/chakra-ui/issues/1118

For the maintainers: this seems to be a desirable pattern – allow to opt out from rendering stuff until necessary, for performance reasons.

1reaction
ljosberinncommented, Aug 13, 2020

hey @nielsdB97, we’re currently looking into this and wanted to let you know you technically have a minor flaw in there: your sandbox returns one large tree, which will get transpiled to react elements. console.log gets executed during this process. The TabPanel can only begin controlling its children after.

However, the issue persists even when separating TabPanels into separate components, so it was not for naught and we’re fixing it 😃

https://codesandbox.io/s/chakra-tabs-mounting-early-forked-f60l4?file=/src/index.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

My tabs become inactive when I switch to another tab help ...
I've experienced something similar but it was due to an extension hogging memory. Check the task manager (launcher + esc in chromeOS I...
Read more >
TabControl disposes of controls on inactive tabs - wpf
Basically, to save memory, the TabControl unloads the visual tree that is in its content area and replaces it with a newly crufted...
Read more >
chrome.tabs - Chrome Developers
Use the chrome.tabs API to interact with the browser's tab system. You can use this API to create, modify, and rearrange tabs in...
Read more >
Tabs | Components - BootstrapVue
For navigation based tabs (i.e. tabs that would change the URL), use the <b-nav> component ... and will be un-mounted when the tab...
Read more >
Tabs - Mantine
By default, inactive Tabs.Panel will stay mounted, to unmount inactive tabs, set keepMounted={false} on Tabs. This is useful when you want to render ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found