-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate inline hydration scripts into one (#3244)
* Consolidate inline hydration scripts into one * Adds changeset * Update custom element test * Provide a better name for tracking if we have added a hydration script
- Loading branch information
Showing
20 changed files
with
152 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Consolidates hydration scripts into one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,6 +201,7 @@ ${extra}` | |
_metadata: { | ||
renderers, | ||
pathname, | ||
needsHydrationStyles: false | ||
}, | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
customElements.define('astro-island', class extends HTMLElement { | ||
async connectedCallback(){ | ||
const [ { default: setup } ] = await Promise.all([ | ||
import(this.getAttribute('directive-url')), | ||
import(this.getAttribute('before-hydration-url')) | ||
]); | ||
const opts = JSON.parse(this.getAttribute('opts')); | ||
setup(this, opts, async () => { | ||
const propsStr = this.getAttribute('props'); | ||
const props = propsStr ? JSON.parse(propsStr) : {}; | ||
const rendererUrl = this.getAttribute('renderer-url'); | ||
const [ | ||
{ default: Component }, | ||
{ default: hydrate } | ||
] = await Promise.all([ | ||
import(this.getAttribute('component-url')), | ||
rendererUrl ? import(rendererUrl) : () => () => {} | ||
]); | ||
return (el, children) => hydrate(el)(Component, props, children); | ||
}); | ||
} | ||
}); | ||
*/ | ||
|
||
/** | ||
* This is a minified version of the above. If you modify the above you need to | ||
* copy/paste it into a .js file and then run: | ||
* > node_modules/.bin/terser --mangle --compress -- file.js | ||
* | ||
* And copy/paste the result below | ||
*/ | ||
export const islandScript = `customElements.define("astro-island",class extends HTMLElement{async connectedCallback(){const[{default:t}]=await Promise.all([import(this.getAttribute("directive-url")),import(this.getAttribute("before-hydration-url"))]);const e=JSON.parse(this.getAttribute("opts"));t(this,e,(async()=>{const t=this.getAttribute("props");const e=t?JSON.parse(t):{};const r=this.getAttribute("renderer-url");const[{default:s},{default:i}]=await Promise.all([import(this.getAttribute("component-url")),r?import(r):()=>()=>{}]);return(t,r)=>i(t)(s,e,r)}))}});`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.