Fix location of SolidJS pre-hydration code (#3140)

* Run before hydration instead of inlining a script after each component
This commit is contained in:
hippotastic 2022-04-19 20:37:27 +02:00 committed by GitHub
parent cfa11eecbf
commit 5e28b79095
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/solid-js': patch
---
Fix location of SolidJS pre-hydration code

View file

@ -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(
() =>

View file

@ -20,7 +20,7 @@ function renderToStaticMarkup(Component, props, children) {
})
);
return {
html: html + `<script>window._$HY||(_$HY={events:[],completed:new WeakSet,r:{}})</script>`,
html: html,
};
}