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

Solid integration renders script tags after each component instance, even non-hydrated ones #3132

Closed
1 task done
hippotastic opened this issue Apr 18, 2022 · 2 comments · Fixed by #3140
Closed
1 task done

Comments

@hippotastic
Copy link
Contributor

hippotastic commented Apr 18, 2022

What version of astro are you using?

1.0.0-beta.12

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

None

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the Bug

When rendering components using the @astrojs/solid-js integration, Astro always renders an additional <script>window._$HY||(_$HY={events:[],completed:new WeakSet,r:{}})</script> tag after each component used on a page.

This does not only cause loads of duplicate script tags on pages using many components (or even the same component multiple times), but it even happens for components that do not specify any client: prop and should therefore not include any JS at all.

In the minimal reproduction example, check the frame source code of the rendered page and see the script tag. Remove the client:visible prop from the Counter in src/pages/index.astro and see that the script tag still gets appended.

Link to Minimal Reproducible Example

https://stackblitz.com/github/withastro/astro/tree/latest/examples/framework-solid?on=stackblitz

Participation

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

Additional note: If someone is able to explain why that script tag currently gets appended to each rendered html in line 23 here, I can also try to contribute a PR to fix that behavior.

@hippotastic
Copy link
Contributor Author

hippotastic commented Apr 18, 2022

I just had a chat with @ryansolid on Discord about this and we discussed that the following behavior would solve the issue:

  • Only run the script in case any hydration of solid components is supposed to occur on the page being rendered.
  • Only run the script once per page, not multiple times.
  • Run the script before any hydration occurs.
    • If we keep doing this with an inline <script> block, given that all hydration is deferred anyway, this script block could be placed before the closing body tag, or after the first solid component that is using a client: prop on the page.
    • [Note by Hippo] Maybe there's an even better place: The code could be run inside the hydration function itself, before calling hydrate!

I'll submit a PR to change Astro's Solid integration as outlined above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant