Skip to content

Commit a776709

Browse files
committed
Add test
1 parent 701a328 commit a776709

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

integration/client-data-test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,85 @@ test.describe("Client Data", () => {
909909
expect(logs).toEqual(["running parent client loader"]);
910910
console.error = _consoleError;
911911
});
912+
913+
test("hydrating clientLoader redirects trigger new .data requests to the server", async ({
914+
page,
915+
}) => {
916+
appFixture = await createAppFixture(
917+
await createFixture({
918+
files: {
919+
"react-router.config.ts": reactRouterConfig({
920+
splitRouteModules,
921+
}),
922+
"app/root.tsx": js`
923+
import { Outlet, Scripts } from "react-router"
924+
925+
let count = 1;
926+
export function loader() {
927+
return count++;
928+
}
929+
930+
export default function Root({ loaderData }) {
931+
return (
932+
<html>
933+
<head></head>
934+
<body>
935+
<main>
936+
<p id="root-data">{loaderData}</p>
937+
<Outlet />
938+
</main>
939+
<Scripts />
940+
</body>
941+
</html>
942+
);
943+
}
944+
`,
945+
"app/routes/parent.tsx": js`
946+
import { Outlet } from 'react-router'
947+
let count = 1;
948+
export function loader() {
949+
return count++;
950+
}
951+
export default function Component({ loaderData }) {
952+
return (
953+
<>
954+
<p id="parent-data">{loaderData}</p>
955+
<Outlet/>
956+
</>
957+
);
958+
}
959+
export function shouldRevalidate() {
960+
return false;
961+
}
962+
`,
963+
"app/routes/parent.a.tsx": js`
964+
import { redirect } from 'react-router'
965+
export function clientLoader() {
966+
return redirect('/parent/b');
967+
}
968+
clientLoader.hydrate = true;
969+
export default function Component({ loaderData }) {
970+
return <p>Should not see me</p>;
971+
}
972+
`,
973+
"app/routes/parent.b.tsx": js`
974+
export default function Component({ loaderData }) {
975+
return <p id="b">Hi!</p>;
976+
}
977+
`,
978+
},
979+
})
980+
);
981+
let app = new PlaywrightFixture(appFixture, page);
982+
983+
await app.goto("/parent/a");
984+
await page.waitForSelector("#b");
985+
// Root re-runs
986+
await expect(page.locator("#root-data")).toHaveText("2");
987+
// But parent opted out of revalidation
988+
await expect(page.locator("#parent-data")).toHaveText("1");
989+
await expect(page.locator("#b")).toHaveText("Hi!");
990+
});
912991
});
913992

914993
test.describe("clientLoader - lazy route module", () => {

0 commit comments

Comments
 (0)