Fix location of SolidJS pre-hydration code (#3140)
* Run before hydration instead of inlining a script after each component
This commit is contained in:
parent
cfa11eecbf
commit
5e28b79095
3 changed files with 11 additions and 1 deletions
5
.changeset/eight-pumas-repeat.md
Normal file
5
.changeset/eight-pumas-repeat.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/solid-js': patch
|
||||
---
|
||||
|
||||
Fix location of SolidJS pre-hydration code
|
|
@ -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(
|
||||
() =>
|
||||
|
|
|
@ -20,7 +20,7 @@ function renderToStaticMarkup(Component, props, children) {
|
|||
})
|
||||
);
|
||||
return {
|
||||
html: html + `<script>window._$HY||(_$HY={events:[],completed:new WeakSet,r:{}})</script>`,
|
||||
html: html,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue