You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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 insrc/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
The text was updated successfully, but these errors were encountered: