fix: twind style generation in islands (#830)

Fixes #778
This commit is contained in:
Luca Casonato
2022-10-11 11:15:12 +02:00
committed by GitHub
parent 0cb05d1dac
commit 9ee03e09bb
2 changed files with 23 additions and 9 deletions
+9 -4
View File
@@ -18,11 +18,15 @@ export default function(state) { hydrate(options, state); }`;
render(ctx) {
sheet.reset(undefined);
const res = ctx.render();
const cssText = [...sheet.target].join("\n");
const cssTexts = [...sheet.target];
const snapshot = sheet.reset();
const scripts = [];
let cssText: string;
if (res.requiresHydration) {
const precedences = snapshot[1];
const precedences = snapshot[1] as number[];
cssText = cssTexts.map((cssText, i) =>
`${cssText}/*${precedences[i].toString(36)}*/`
).join("\n");
const mappings: (string | [string, string])[] = [];
for (
const [key, value] of (snapshot[3] as Map<string, string>).entries()
@@ -33,8 +37,9 @@ export default function(state) { hydrate(options, state); }`;
mappings.push([key, value]);
}
}
const state = [precedences, mappings];
scripts.push({ entrypoint: "main", state });
scripts.push({ entrypoint: "main", state: mappings });
} else {
cssText = cssTexts.join("\n");
}
return {
scripts,