fix: CSS modules not working in _app/_layout/_error and across routes in dev (#3764)
Islands used in `_app.tsx`, `_layout.tsx`, or `_error.tsx` are discovered after `<head>` has already rendered, so their CSS `<link>` tags were never injected. `FreshScripts` (at end of `<body>`) now emits late CSS for any islands missed by `RemainingHead`, using an `injectedCss` set to avoid duplicates. In dev mode, `collectCss` only walked the `fresh:client-entry` module graph, missing CSS imported by island modules. The dev server now also walks `fresh-island::*` module graphs when collecting CSS. Note: late-injected `<link>` tags in `<body>` may cause a brief flash of unstyled content — this is inherent to the problem since `<head>` renders before `<body>` islands are discovered. Closes #3633 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
14f895517e
commit
36dd6375eb
@@ -0,0 +1,3 @@
|
||||
.nav {
|
||||
background-color: rgb(30, 30, 30);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// @ts-ignore upstream issue https://github.com/denoland/deno/issues/30560
|
||||
import styles from "./AppNav.module.css";
|
||||
|
||||
export function AppNav() {
|
||||
return (
|
||||
<nav class={`app-nav ${styles.nav}`}>
|
||||
<span>Fresh</span>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { PageProps } from "fresh";
|
||||
import { AppNav } from "../islands/AppNav.tsx";
|
||||
|
||||
export default function App({ Component }: PageProps) {
|
||||
return (
|
||||
@@ -9,6 +10,7 @@ export default function App({ Component }: PageProps) {
|
||||
<meta name="custom" content="foo" />
|
||||
</head>
|
||||
<body>
|
||||
<AppNav />
|
||||
<Component />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { CssModules } from "../../islands/CssModules.tsx";
|
||||
|
||||
export default function Page2() {
|
||||
return (
|
||||
<div>
|
||||
<CssModules />
|
||||
<p class="page2-marker">page2</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user