Skip to content

Commit 549e5d0

Browse files
committed
Merge branch 'dev' into brophdawg11/test-refactor
2 parents 465a4b8 + cbcbf30 commit 549e5d0

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

.changeset/little-timers-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
[UNSTABLE] Pass `<Scripts nonce>` value through to the underlying `importmap` `script` tag when using `future.unstable_subResourceIntegrity`

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
- developit
107107
- dgrijuela
108108
- DigitalNaut
109+
- dimmageiras
109110
- DimaAmega
110111
- dmitrytarassov
111112
- dogxii

integration/sri-test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
import {
4+
createAppFixture,
5+
createFixture,
6+
js,
7+
} from "./helpers/create-fixture.js";
8+
import type { AppFixture, Fixture } from "./helpers/create-fixture.js";
9+
import { reactRouterConfig } from "./helpers/vite.js";
10+
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
11+
12+
test.describe("CSub-Resource Integrity", () => {
13+
test.use({ javaScriptEnabled: false });
14+
15+
let fixture: Fixture;
16+
let appFixture: AppFixture;
17+
18+
test.beforeAll(async () => {
19+
fixture = await createFixture({
20+
files: {
21+
"react-router.config.ts": reactRouterConfig({
22+
future: { unstable_subResourceIntegrity: true },
23+
}),
24+
"app/root.tsx": js`
25+
import { Links, Meta, Outlet, Scripts } from "react-router";
26+
27+
export default function Root() {
28+
return (
29+
<html>
30+
<head>
31+
<Meta />
32+
<Links />
33+
</head>
34+
<body>
35+
<Outlet />
36+
<Scripts nonce="test-nonce-123" />
37+
</body>
38+
</html>
39+
);
40+
}
41+
`,
42+
},
43+
});
44+
appFixture = await createAppFixture(fixture);
45+
});
46+
47+
test("includes an importmap", async ({ page }) => {
48+
let app = new PlaywrightFixture(appFixture, page);
49+
await app.goto("/");
50+
let json = await page.locator('script[type="importmap"]').innerText();
51+
let importMap = JSON.parse(json);
52+
expect(Object.keys(importMap.integrity).length).toBeGreaterThan(0);
53+
for (let key in importMap.integrity) {
54+
if (key.includes("manifest")) continue;
55+
let value = importMap.integrity[key];
56+
expect(value).toMatch(/^sha384-/);
57+
58+
let linkEl = page.locator(`link[rel="modulepreload"][href="${key}"]`);
59+
expect(await linkEl.getAttribute("href")).toBe(key);
60+
expect(await linkEl.getAttribute("integrity")).toBe(value);
61+
62+
let scriptEl = page.locator(`script[type="module"]`);
63+
expect(await scriptEl.innerText()).toContain(key);
64+
}
65+
});
66+
67+
test("includes a nonce on the importmap script", async ({ page }) => {
68+
let app = new PlaywrightFixture(appFixture, page);
69+
await app.goto("/");
70+
expect(
71+
await page.locator('script[type="importmap"]').getAttribute("nonce"),
72+
).toBe("test-nonce-123");
73+
});
74+
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ import(${JSON.stringify(manifest.entry.module)});`;
907907
<>
908908
{typeof manifest.sri === "object" ? (
909909
<script
910+
{...scriptProps}
910911
rr-importmap=""
911912
type="importmap"
912913
suppressHydrationWarning

0 commit comments

Comments
 (0)