Skip to content

Commit 114aba2

Browse files
authored
Minor client data implementation cleanups (#8236)
1 parent e3ab562 commit 114aba2

File tree

1 file changed

+99
-1
lines changed

1 file changed

+99
-1
lines changed

integration/client-data-test.ts

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,61 @@ test.describe("Client Data", () => {
404404
expect(html).toMatch("Child Client Loader");
405405
});
406406

407-
test("clientLoader.hydrate is automatically implied when no server loader exists", async ({
407+
test("HydrateFallback is not rendered if clientLoader.hydrate is not set (w/server loader)", async ({
408+
page,
409+
}) => {
410+
let fixture = await createFixture({
411+
files: {
412+
...getFiles({
413+
parentClientLoader: false,
414+
parentClientLoaderHydrate: false,
415+
childClientLoader: false,
416+
childClientLoaderHydrate: false,
417+
}),
418+
// Blow away parent.child.tsx with our own version
419+
"app/routes/parent.child.tsx": js`
420+
import * as React from 'react';
421+
import { json } from '@remix-run/node';
422+
import { useLoaderData } from '@remix-run/react';
423+
export function loader() {
424+
return json({
425+
message: "Child Server Loader Data",
426+
});
427+
}
428+
export async function clientLoader({ serverLoader }) {
429+
await new Promise(r => setTimeout(r, 100));
430+
return {
431+
message: "Child Client Loader Data",
432+
};
433+
}
434+
export function HydrateFallback() {
435+
return <p>SHOULD NOT SEE ME</p>
436+
}
437+
export default function Component() {
438+
let data = useLoaderData();
439+
return <p id="child-data">{data.message}</p>;
440+
}
441+
`,
442+
},
443+
});
444+
appFixture = await createAppFixture(fixture);
445+
446+
// Ensure initial document request contains the child fallback _and_ the
447+
// subsequent streamed/resolved deferred data
448+
let doc = await fixture.requestDocument("/parent/child");
449+
let html = await doc.text();
450+
expect(html).toMatch("Child Server Loader Data");
451+
expect(html).not.toMatch("SHOULD NOT SEE ME");
452+
453+
let app = new PlaywrightFixture(appFixture, page);
454+
455+
await app.goto("/parent/child");
456+
await page.waitForSelector("#child-data");
457+
html = await app.getHtml("main");
458+
expect(html).toMatch("Child Server Loader Data");
459+
});
460+
461+
test("clientLoader.hydrate is automatically implied when no server loader exists (w HydrateFallback)", async ({
408462
page,
409463
}) => {
410464
appFixture = await createAppFixture(
@@ -447,6 +501,50 @@ test.describe("Client Data", () => {
447501
html = await app.getHtml("main");
448502
expect(html).toMatch("Loader Data (clientLoader only)");
449503
});
504+
505+
test("clientLoader.hydrate is automatically implied when no server loader exists (w/o HydrateFallback)", async ({
506+
page,
507+
}) => {
508+
appFixture = await createAppFixture(
509+
await createFixture({
510+
files: {
511+
...getFiles({
512+
parentClientLoader: false,
513+
parentClientLoaderHydrate: false,
514+
childClientLoader: false,
515+
childClientLoaderHydrate: false,
516+
}),
517+
// Blow away parent.child.tsx with our own version without a server loader
518+
"app/routes/parent.child.tsx": js`
519+
import * as React from 'react';
520+
import { useLoaderData } from '@remix-run/react';
521+
// Even without setting hydrate=true, this should run on hydration
522+
export async function clientLoader({ serverLoader }) {
523+
await new Promise(r => setTimeout(r, 100));
524+
return {
525+
message: "Loader Data (clientLoader only)",
526+
};
527+
}
528+
export default function Component() {
529+
let data = useLoaderData();
530+
return <p id="child-data">{data.message}</p>;
531+
}
532+
`,
533+
},
534+
})
535+
);
536+
let app = new PlaywrightFixture(appFixture, page);
537+
538+
await app.goto("/parent/child");
539+
let html = await app.getHtml();
540+
expect(html).toMatch(
541+
"💿 Hey developer 👋. You can provide a way better UX than this"
542+
);
543+
expect(html).not.toMatch("child-data");
544+
await page.waitForSelector("#child-data");
545+
html = await app.getHtml("main");
546+
expect(html).toMatch("Loader Data (clientLoader only)");
547+
});
450548
});
451549

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

0 commit comments

Comments
 (0)