fix: twind styles not updated on partial nav (#2017)
This commit is contained in:
+17
-21
@@ -17,32 +17,28 @@ export default function(state) { hydrate(options, state); }`;
|
|||||||
entrypoints: { "main": main },
|
entrypoints: { "main": main },
|
||||||
async renderAsync(ctx) {
|
async renderAsync(ctx) {
|
||||||
sheet.reset(undefined);
|
sheet.reset(undefined);
|
||||||
const res = await ctx.renderAsync();
|
await ctx.renderAsync();
|
||||||
const cssTexts = [...sheet.target];
|
const cssTexts = [...sheet.target];
|
||||||
const snapshot = sheet.reset();
|
const snapshot = sheet.reset();
|
||||||
const scripts = [];
|
const precedences = snapshot[1] as number[];
|
||||||
let cssText: string;
|
|
||||||
if (res.requiresHydration) {
|
const cssText = cssTexts.map((cssText, i) =>
|
||||||
const precedences = snapshot[1] as number[];
|
`${cssText}/*${precedences[i].toString(36)}*/`
|
||||||
cssText = cssTexts.map((cssText, i) =>
|
).join("\n");
|
||||||
`${cssText}/*${precedences[i].toString(36)}*/`
|
|
||||||
).join("\n");
|
const mappings: (string | [string, string])[] = [];
|
||||||
const mappings: (string | [string, string])[] = [];
|
for (
|
||||||
for (
|
const [key, value] of (snapshot[3] as Map<string, string>).entries()
|
||||||
const [key, value] of (snapshot[3] as Map<string, string>).entries()
|
) {
|
||||||
) {
|
if (key === value) {
|
||||||
if (key === value) {
|
mappings.push(key);
|
||||||
mappings.push(key);
|
} else {
|
||||||
} else {
|
mappings.push([key, value]);
|
||||||
mappings.push([key, value]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
scripts.push({ entrypoint: "main", state: mappings });
|
|
||||||
} else {
|
|
||||||
cssText = cssTexts.join("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
scripts,
|
scripts: [{ entrypoint: "main", state: mappings }],
|
||||||
styles: [{ cssText, id: STYLE_ELEMENT_ID }],
|
styles: [{ cssText, id: STYLE_ELEMENT_ID }],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-6
@@ -24,14 +24,10 @@ export default function(state) { hydrate(options, state); }`;
|
|||||||
name: "twind",
|
name: "twind",
|
||||||
entrypoints: { "main": main },
|
entrypoints: { "main": main },
|
||||||
async renderAsync(ctx) {
|
async renderAsync(ctx) {
|
||||||
const res = await ctx.renderAsync();
|
await ctx.renderAsync();
|
||||||
const cssText = stringify(sheet.target);
|
const cssText = stringify(sheet.target);
|
||||||
const scripts = [];
|
|
||||||
if (res.requiresHydration) {
|
|
||||||
scripts.push({ entrypoint: "main", state: [] });
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
scripts,
|
scripts: [{ entrypoint: "main", state: [] }],
|
||||||
styles: [{ cssText, id: STYLE_ELEMENT_ID }],
|
styles: [{ cssText, id: STYLE_ELEMENT_ID }],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,25 +4,32 @@
|
|||||||
|
|
||||||
import * as $0 from "./routes/check-duplication.tsx";
|
import * as $0 from "./routes/check-duplication.tsx";
|
||||||
import * as $1 from "./routes/insert-cssrules.tsx";
|
import * as $1 from "./routes/insert-cssrules.tsx";
|
||||||
import * as $2 from "./routes/static.tsx";
|
import * as $2 from "./routes/island_twind/_layout.tsx";
|
||||||
import * as $3 from "./routes/unused.tsx";
|
import * as $3 from "./routes/island_twind/blue.tsx";
|
||||||
import * as $4 from "./routes/unused_tw.tsx";
|
import * as $4 from "./routes/island_twind/index.tsx";
|
||||||
|
import * as $5 from "./routes/static.tsx";
|
||||||
|
import * as $6 from "./routes/unused.tsx";
|
||||||
|
import * as $7 from "./routes/unused_tw.tsx";
|
||||||
import * as $$0 from "./islands/CheckDuplication.tsx";
|
import * as $$0 from "./islands/CheckDuplication.tsx";
|
||||||
import * as $$1 from "./islands/InsertCssrules.tsx";
|
import * as $$1 from "./islands/InsertCssrules.tsx";
|
||||||
|
import { Manifest } from "$fresh/server.ts";
|
||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
"./routes/check-duplication.tsx": $0,
|
"./routes/check-duplication.tsx": $0,
|
||||||
"./routes/insert-cssrules.tsx": $1,
|
"./routes/insert-cssrules.tsx": $1,
|
||||||
"./routes/static.tsx": $2,
|
"./routes/island_twind/_layout.tsx": $2,
|
||||||
"./routes/unused.tsx": $3,
|
"./routes/island_twind/blue.tsx": $3,
|
||||||
"./routes/unused_tw.tsx": $4,
|
"./routes/island_twind/index.tsx": $4,
|
||||||
|
"./routes/static.tsx": $5,
|
||||||
|
"./routes/unused.tsx": $6,
|
||||||
|
"./routes/unused_tw.tsx": $7,
|
||||||
},
|
},
|
||||||
islands: {
|
islands: {
|
||||||
"./islands/CheckDuplication.tsx": $$0,
|
"./islands/CheckDuplication.tsx": $$0,
|
||||||
"./islands/InsertCssrules.tsx": $$1,
|
"./islands/InsertCssrules.tsx": $$1,
|
||||||
},
|
},
|
||||||
baseUrl: import.meta.url,
|
baseUrl: import.meta.url,
|
||||||
};
|
} satisfies Manifest;
|
||||||
|
|
||||||
export default manifest;
|
export default manifest;
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { Partial } from "$fresh/runtime.ts";
|
||||||
|
import { LayoutProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
export default function Layout(
|
||||||
|
{ Component }: LayoutProps<unknown, unknown>,
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<div f-client-nav>
|
||||||
|
<nav>
|
||||||
|
<ul class="text-blue-500 underline m-8 flex gap-12">
|
||||||
|
<li>
|
||||||
|
<a href="/island_twind">red bg</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="/island_twind/blue">blue bg</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="/island_twind/no-route-here">404 page</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<div class="mx-auto max-w-screen-md">
|
||||||
|
<Partial name="main-content">
|
||||||
|
<Component />
|
||||||
|
</Partial>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export default function Blue() {
|
||||||
|
return (
|
||||||
|
<div class="bg-blue-500">
|
||||||
|
Should have blue bg
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<div class="bg-red-500">
|
||||||
|
Should have red bg
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { assert, assertEquals, assertMatch, delay, puppeteer } from "./deps.ts";
|
|||||||
import { cmpStringArray } from "./fixture_twind_hydrate/utils/utils.ts";
|
import { cmpStringArray } from "./fixture_twind_hydrate/utils/utils.ts";
|
||||||
import {
|
import {
|
||||||
startFreshServer,
|
startFreshServer,
|
||||||
|
waitForStyle,
|
||||||
withFakeServe,
|
withFakeServe,
|
||||||
withFresh,
|
withFresh,
|
||||||
withPageName,
|
withPageName,
|
||||||
@@ -385,3 +386,22 @@ Deno.test("don't duplicate css class with twindV1", async () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("render styles from partial update", async () => {
|
||||||
|
await withPageName(
|
||||||
|
"./tests/fixture_twind_hydrate/main.ts",
|
||||||
|
async (page, address) => {
|
||||||
|
await page.goto(`${address}/island_twind`);
|
||||||
|
await page.click(`a[href="/island_twind/blue"]`);
|
||||||
|
|
||||||
|
await page.waitForSelector(".bg-blue-500");
|
||||||
|
|
||||||
|
await waitForStyle(
|
||||||
|
page,
|
||||||
|
".bg-blue-500",
|
||||||
|
"backgroundColor",
|
||||||
|
"rgb(59, 130, 246)",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user