If you lazy-load a component including a Shiitake, the content sometimes doesn't render. This isn't your fault; it's due to a design flaw in React that the developers have said they aren't going to fix. Here's why it happens:
- The lazy-loaded component is downloaded, and the virtual DOM is constructed, with
display: none on the topmost element. While this is happening, the Suspense fallback is being displayed.
- The DOM is rendered, and all JS is executed.
- Depending on timing, this is when Shiitake measures itself to figure out how much vertical space is being used. Since the parent has
display: none, the measured height is zero.
- React hides the
Suspense fallback, and removes display: none. This action is not linked to the React lifecycle, and doesn't fire any sort of event, so there's no way to detect that this is happening.
- If the user doesn't trigger a
Shiitake rerender by resizing the window or something, the content is rendered inside a height: 0 element, which makes it invisible to the user.
In my project, I worked around the issue by creating a wrapper component around Shiitake which goes up the DOM tree looking for display: none, and polling for that style's removal. It's very hacky, but it works.
If you fix this, you'll have the only popular line-clamping component which can safely be lazy-loaded. I checked the others. :) If you like, I can ask my boss whether my workaround can be open sourced so you can use it as a dependency.
If you lazy-load a component including a
Shiitake, the content sometimes doesn't render. This isn't your fault; it's due to a design flaw in React that the developers have said they aren't going to fix. Here's why it happens:display: noneon the topmost element. While this is happening, theSuspensefallback is being displayed.display: none, the measured height is zero.Suspensefallback, and removesdisplay: none. This action is not linked to the React lifecycle, and doesn't fire any sort of event, so there's no way to detect that this is happening.Shiitakererender by resizing the window or something, the content is rendered inside aheight: 0element, which makes it invisible to the user.In my project, I worked around the issue by creating a wrapper component around
Shiitakewhich goes up the DOM tree looking fordisplay: none, and polling for that style's removal. It's very hacky, but it works.If you fix this, you'll have the only popular line-clamping component which can safely be lazy-loaded. I checked the others. :) If you like, I can ask my boss whether my workaround can be open sourced so you can use it as a dependency.