[Tabs] Improve tab panels mounting behavior
See original GitHub issueBased on #21241, we might have an opportunity to improve the TabPanel
mounting behavior. We can potentially fix these problems:
- Lost states between different panels (by keeping the panels mounted)
- Improve the performance of panel transitions (by mounting the panels ahead of time)
- Improve the SEO support (by rendering all the panels’s content)
I have used the following benchmark list https://trello.com/c/JM6Zh3YW/2642-tabs to look at what the others are doing
- hidden prop with full rendering and no option to disable it https://github.com/reach/reach-ui/blob/115eb680bae13e7e097c9a6cd3047c06530ee880/packages/tabs/src/index.tsx#L643
- Reach UI
- Reakit
- Garden
- Chakra
- React Bootstrap
- lazy render the content of the tab panels, keep them mounted when moving to a different tab
- Antd (plus a
forceRender
prop to render all the panels)
- only render the active tab panel
- Base Web (plus a
renderAll
prop to render all the panels) - Material-UI
- JetBrains
- Semantic UI
- AltasKit
- Polaris
- render in two passes, first the active panel, then all the panels
- react-swipeable-views
In the future, React will likely provide better support for offscreen rendering
What do you guys think between these different tradeoffs? It seems that we need, at least, a way to enable the mounting of all the panels.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:49
- Comments:17 (2 by maintainers)
Top Results From Across the Web
[Tabs] Improve tab panels mounting behavior #21250 - GitHub
Based on #21241, we might have an opportunity to improve the TabPanel mounting behavior. We can potentially fix these problems:.
Read more >React recreates my component on each material ui tab switch
This is the expected behaviour for a component. Before it gets mounted, the constructor gets called. It might be worth giving the docs...
Read more >Let's talk about Native HTML Tabs - daverupert.com
Level 1: HTML needs a tabs element. ... The <code>tab-bar</code> affordance can use shadow-dom to establish a styleable tab-bar and panels.
Read more >Brick, Stone, Granite or Marble. Tabs Wall Systems • 4515 ...
Prior to installing the Tabs Panel, it is extremely important that the substrate of choice has been properly prepared and covered with a...
Read more >Tabs - Reach UI
You can render any other elements you want inside of Tabs , but TabList should only render Tab elements, and TabPanels should only...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@oliviertassinari I use simple solution to have always mounted TabPanels:
If anybody wants to make a deep dive into React 18 then I would suggest investigating wrapping the panel content in
React.Suspense
. Eventually you’ll want to use an upcoming Offscreen API for the hidden TabPanels so React can de-prioritize the hidden panel (and persist state when it gets hidden). There are also interesting questions like selective hydration for hidden TabPanels that would be enabled byReact.Suspense
and how this behaves when the user starts navigating to a TabPanel before it is hydrated.I don’t have a full picture for this yet hence why I suggest that somebody investigates this area since I believe tabs can really make use of React 18.
Edit:
I think it’s safe to assume that this will happen.