Skip to content

Commit 1f21bdf

Browse files
committed
do not transport SRI info in manifest, only in the importmap
1 parent f3849b2 commit 1f21bdf

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

packages/react-router/lib/dom/ssr/components.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -776,21 +776,28 @@ import(${JSON.stringify(manifest.entry.module)});`;
776776

777777
let preloads = isHydrated
778778
? []
779-
: manifest.entry.imports.concat(
780-
getModuleLinkHrefs(matches, manifest, {
781-
includeHydrateFallback: true,
782-
})
779+
: dedupe(
780+
manifest.entry.imports.concat(
781+
getModuleLinkHrefs(matches, manifest, {
782+
includeHydrateFallback: true,
783+
})
784+
)
783785
);
784786

787+
let sri = typeof manifest.sri === "object" ? manifest.sri : {};
788+
785789
return isHydrated ? null : (
786790
<>
787791
{manifest.sri ? (
788792
<script
789793
type="importmap"
794+
suppressHydrationWarning
790795
dangerouslySetInnerHTML={{
791-
__html: JSON.stringify({
792-
integrity: manifest.sri,
793-
}),
796+
__html: sri
797+
? JSON.stringify({
798+
integrity: sri,
799+
})
800+
: "",
794801
}}
795802
/>
796803
) : null}
@@ -799,22 +806,22 @@ import(${JSON.stringify(manifest.entry.module)});`;
799806
rel="modulepreload"
800807
href={manifest.url}
801808
crossOrigin={props.crossOrigin}
802-
integrity={manifest.sri?.[manifest.url]}
809+
integrity={sri[manifest.url]}
803810
/>
804811
) : null}
805812
<link
806813
rel="modulepreload"
807814
href={manifest.entry.module}
808815
crossOrigin={props.crossOrigin}
809-
integrity={manifest.sri?.[manifest.entry.module]}
816+
integrity={sri[manifest.entry.module]}
810817
/>
811-
{dedupe(preloads).map((path) => (
818+
{preloads.map((path) => (
812819
<link
813820
key={path}
814821
rel="modulepreload"
815822
href={path}
816823
crossOrigin={props.crossOrigin}
817-
integrity={manifest.sri?.[path]}
824+
integrity={sri[path]}
818825
/>
819826
))}
820827
{initialScripts}

packages/react-router/lib/dom/ssr/entry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ export interface AssetsManifest {
6060
timestamp?: number;
6161
runtime: string;
6262
};
63-
sri?: Record<string, string>;
63+
sri?: Record<string, string> | true;
6464
}

packages/react-router/lib/dom/ssr/fog-of-war.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function isFogOfWarEnabled(ssr: boolean) {
3131
}
3232

3333
export function getPartialManifest(
34-
manifest: AssetsManifest,
34+
{ sri, ...manifest }: AssetsManifest,
3535
router: DataRouter
3636
) {
3737
// Start with our matches for this pathname
@@ -64,6 +64,7 @@ export function getPartialManifest(
6464
return {
6565
...manifest,
6666
routes: initialRoutes,
67+
sri: true,
6768
};
6869
}
6970

playground/framework/app/root.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
1+
import {
2+
Link,
3+
Links,
4+
Meta,
5+
Outlet,
6+
Scripts,
7+
ScrollRestoration,
8+
} from "react-router";
29

310
export function Layout({ children }: { children: React.ReactNode }) {
411
return (
512
<html lang="en">
613
<head>
714
<meta charSet="utf-8" />
815
<meta name="viewport" content="width=device-width, initial-scale=1" />
9-
16+
1017
<Meta />
1118
<Links />
1219
</head>
1320
<body>
21+
<ul>
22+
<li>
23+
<Link prefetch="intent" to="/">
24+
Home
25+
</Link>
26+
</li>
27+
<li>
28+
<Link prefetch="intent" to="/products/abc">
29+
Product
30+
</Link>
31+
</li>
32+
</ul>
1433
{children}
1534
<ScrollRestoration />
1635
<Scripts />

0 commit comments

Comments
 (0)