fix: twind styles not updated on partial nav (#2017)

This commit is contained in:
Marvin Hagemeister
2023-11-06 14:04:43 +01:00
committed by GitHub
parent 8b846816a6
commit c172af67cf
7 changed files with 96 additions and 34 deletions
+17 -21
View File
@@ -17,32 +17,28 @@ export default function(state) { hydrate(options, state); }`;
entrypoints: { "main": main },
async renderAsync(ctx) {
sheet.reset(undefined);
const res = await ctx.renderAsync();
await ctx.renderAsync();
const cssTexts = [...sheet.target];
const snapshot = sheet.reset();
const scripts = [];
let cssText: string;
if (res.requiresHydration) {
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()
) {
if (key === value) {
mappings.push(key);
} else {
mappings.push([key, value]);
}
const precedences = snapshot[1] as number[];
const 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()
) {
if (key === value) {
mappings.push(key);
} else {
mappings.push([key, value]);
}
scripts.push({ entrypoint: "main", state: mappings });
} else {
cssText = cssTexts.join("\n");
}
return {
scripts,
scripts: [{ entrypoint: "main", state: mappings }],
styles: [{ cssText, id: STYLE_ELEMENT_ID }],
};
},
+2 -6
View File
@@ -24,14 +24,10 @@ export default function(state) { hydrate(options, state); }`;
name: "twind",
entrypoints: { "main": main },
async renderAsync(ctx) {
const res = await ctx.renderAsync();
await ctx.renderAsync();
const cssText = stringify(sheet.target);
const scripts = [];
if (res.requiresHydration) {
scripts.push({ entrypoint: "main", state: [] });
}
return {
scripts,
scripts: [{ entrypoint: "main", state: [] }],
styles: [{ cssText, id: STYLE_ELEMENT_ID }],
};
},