Skip to content

Commit

Permalink
Fix location of SolidJS pre-hydration code (#3140)
Browse files Browse the repository at this point in the history
* Run before hydration instead of inlining a script after each component
  • Loading branch information
hippotastic authored Apr 19, 2022
1 parent cfa11ee commit 5e28b79
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eight-pumas-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/solid-js': patch
---

Fix location of SolidJS pre-hydration code
5 changes: 5 additions & 0 deletions packages/integrations/solid/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { sharedConfig } from 'solid-js';
import { hydrate, createComponent } from 'solid-js/web';

export default (element) => (Component, props, childHTML) => {
// Prepare global object expected by Solid's hydration logic
if (!window._$HY) {
window._$HY = { events: [], completed: new WeakSet, r: {} };
}
// Perform actual hydration
let children;
hydrate(
() =>
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/solid/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function renderToStaticMarkup(Component, props, children) {
})
);
return {
html: html + `<script>window._$HY||(_$HY={events:[],completed:new WeakSet,r:{}})</script>`,
html: html,
};
}

Expand Down

0 comments on commit 5e28b79

Please sign in to comment.