Skip to content

Shiitake doesn't play well with lazy/Suspense #36

Description

@zioth

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:

  1. 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.
  2. The DOM is rendered, and all JS is executed.
  3. 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.
  4. 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.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions