Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astro fails to load lazy SolidJS components after server startup due to race condition #6912

Closed
1 task done
howagain opened this issue Apr 25, 2023 · 5 comments
Closed
1 task done
Labels
- P2: nice to have Not breaking anything but nice to have (priority) needs response Issue needs response from OP pkg: solid Related to Solid (scope)

Comments

@howagain
Copy link

howagain commented Apr 25, 2023

What version of astro are you using?

2.3.1

Are you using an SSR adapter? If so, which one?

Node

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

When starting up the server for the first time, a top level lazy component does not render on the server and the complete HTML response is sent before that render branch finishes.

I believe that this is because Astro does not await inside components. But it does cache the result of repeated calls to render. Resulting in a race condition.

However, what is interesting is that this behavior is not only intermittent but 3 states are possible.

  1. The component fails to render completely, usually on first startup only. The lazy component is not in the source HTML.
  2. The component flashes for a second before hydration, and then after hydration occurs, it disappears. Usually this happens on the second refresh and much more frequently in my more complex production app where hydration takes more time.
  3. The component successfully renders itself, usually after several refreshes. The component is in the source HTML.

In the example provided you'll notice that the text "My App" appears but the buttons below do not appear on first render. But if you refresh the dev server page you will see the buttons appear. Inspect the HTML between attempts and you will see the buttons are not there in the first render but are there in subsequent renders.

*Note in the example provided, I have only seen 1 & 3 occur due to the hydration occurring so fast.

If you are struggling to reproduce, start and stop the dev server between attempts.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-efihju?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@howagain
Copy link
Author

After investigating I think that the issue is better visualized by this fork which shows a suspense fallback message rather than nothing.

I believe it's because according to Solid's tutorial on lazy the first time a component loads in solidJS with lazy it's dynamically loads.

The output is a Component that can be used as normal in our JSX template with the exception that internally it dynamically loads the underlying imported code when it is rendered the first time, halting that branch of rendering until the code is available.

I seem to remember something saying that Astro does not support async in UI components. If that's the case I don't know what a solution would be for this, is there someway to await suspense boundaries in SolidJS?

@howagain
Copy link
Author

If this is an async problem it looks like #6791 maybe would solve this issue.

@matthewp matthewp added the - P2: nice to have Not breaking anything but nice to have (priority) label Apr 28, 2023
@matthewp
Copy link
Contributor

Yep, let's try and get that PR merged.

@natemoo-re natemoo-re added the pkg: solid Related to Solid (scope) label Aug 10, 2023
@florian-lefebvre
Copy link
Member

@howagain does the latest version of the solid integrations resolves the issue on your side?

@florian-lefebvre florian-lefebvre added the needs response Issue needs response from OP label Jan 9, 2024
@matthewp
Copy link
Contributor

matthewp commented Feb 2, 2024

No response, so closing, please open another issue if you have the problem.

@matthewp matthewp closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) needs response Issue needs response from OP pkg: solid Related to Solid (scope)
Projects
None yet
Development

No branches or pull requests

4 participants