Skip to content

Commit

Permalink
Better handling for server islands with editor fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tate-CC committed Jan 22, 2025
1 parent 12c91cc commit 144695d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion javascript-modules/engines/astro-engine/lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Engine {
this.reactRoots.push({Component, props});
return { html: `<div data-react-root=${this.reactRoots.length-1}></div>` };
}

const reactNode = await Component(props);
return { html: renderToStaticMarkup(reactNode) };
},
Expand Down Expand Up @@ -118,12 +118,30 @@ export class Engine {

async renderAstroComponent(target, key, props, globals) {
const component = this.files?.[key];

let encryptionKey;
try{
encryptionKey = window.crypto.subtle.generateKey(
{
name: "AES-GCM",
length: 256,
},
true,
["encrypt", "decrypt"],
)
} catch(err){
console.warn("[Bookshop] Could not generate a key for Astro component. This may cause issues with Astro components that use server-islands")
}

const SSRResult = {
styles: new Set(),
scripts: new Set(),
links: new Set(),
propagation: new Map(),
propagators: new Map(),
serverIslandNameMap: { get: () => "Bookshop" },
key: encryptionKey,
base: "/",
extraHead: [],
componentMetadata: new Map(),
renderers: this.renderers,
Expand Down Expand Up @@ -166,6 +184,9 @@ export class Engine {
flushSync(() => root.render(reactNode));
});
this.reactRoots = [];
target.querySelectorAll("link, [data-island-id]").forEach((node) => {
node.remove();
});
}

async eval(str, props = [{}]) {
Expand Down

0 comments on commit 144695d

Please sign in to comment.