Skip to content

Commit

Permalink
Account for non-default exports
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Jun 13, 2022
1 parent f52864c commit bf25ff1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/astro-island.prebuilt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* to generate this file.
*/

export default `{const i={0:t=>t,1:t=>JSON.parse(t,r),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,r)),5:t=>new Set(JSON.parse(t,r)),6:t=>BigInt(t),7:t=>new URL(t)},r=(t,e)=>{if(t===""||!Array.isArray(e))return e;const[n,s]=e;return n in i?i[n](s):void 0};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"))]),e=JSON.parse(this.getAttribute("opts"));t(this,e,async()=>{const n=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),r):{},s=this.getAttribute("renderer-url"),[{default:o},{default:a}]=await Promise.all([import(this.getAttribute("component-url")),s?import(s):()=>()=>{}]);return(p,l)=>a(p)(o,n,l,{client:this.getAttribute("client")})})}})}`;
export default `{const i={0:t=>t,1:t=>JSON.parse(t,r),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,r)),5:t=>new Set(JSON.parse(t,r)),6:t=>BigInt(t),7:t=>new URL(t)},r=(t,e)=>{if(t===""||!Array.isArray(e))return e;const[n,s]=e;return n in i?i[n](s):void 0};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"))]),e=JSON.parse(this.getAttribute("opts"));t(this,e,async()=>{const n=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),r):{},s=this.getAttribute("renderer-url"),[o,{default:p}]=await Promise.all([import(this.getAttribute("component-url")),s?import(s):()=>()=>{}]),a=o[this.getAttribute("component-export")||"default"];return(l,c)=>p(l)(a,n,c,{client:this.getAttribute("client")})})}})}`;
3 changes: 2 additions & 1 deletion packages/astro/src/runtime/server/astro-island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
const props = this.hasAttribute('props') ? JSON.parse(this.getAttribute('props')!, reviver) : {};
const rendererUrl = this.getAttribute('renderer-url');
const [
{ default: Component },
componentModule,
{ default: hydrate }
] = await Promise.all([
import(this.getAttribute('component-url')!),
rendererUrl ? import(rendererUrl) : () => () => {}
]);
const Component = componentModule[this.getAttribute('component-export') || 'default'];
return (el: HTMLElement, children: string) => hydrate(el)(Component, props, children, { client: this.getAttribute('client') });
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/runtime/server/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export async function generateHydrateScript(

// Add renderer url
if(renderer.clientEntrypoint) {
island.props['component-export'] = componentExport.value;
island.props['renderer-url'] = await result.resolve(renderer.clientEntrypoint);
island.props['props'] = escapeHTML(serializeProps(props));
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/cmd/prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default async function prebuild(...args) {

async function prebuildFile(filepath) {
const tscode = await fs.promises.readFile(filepath, 'utf-8');
const esbuildresult = await esbuild.transform(tscode, { loader: 'ts', minify: true });
const esbuildresult = await esbuild.transform(tscode, {
loader: 'ts', minify: true
});
const rootURL = new URL('../../', import.meta.url);
const rel = path.relative(fileURLToPath(rootURL), filepath)
const mod = `/**
Expand Down

0 comments on commit bf25ff1

Please sign in to comment.