Skip to content

Commit 83ef166

Browse files
authored
Fix a bug with SPA mode when the root route had no children (#8747)
1 parent d518609 commit 83ef166

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

integration/spa-mode-test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,90 @@ test.describe("SPA Mode", () => {
431431
"Index Loader Data"
432432
);
433433
});
434+
435+
test("works for migration apps with only a root route and no loader", async ({
436+
page,
437+
}) => {
438+
fixture = await createFixture({
439+
compiler: "vite",
440+
spaMode: true,
441+
files: {
442+
"vite.config.ts": js`
443+
import { defineConfig } from "vite";
444+
import { vitePlugin as remix } from "@remix-run/dev";
445+
446+
export default defineConfig({
447+
plugins: [remix({
448+
// We don't want to pick up the app/routes/_index.tsx file from
449+
// the template and instead want to use only the src/root.tsx
450+
// file below
451+
appDirectory: "src",
452+
ssr: false,
453+
})],
454+
});
455+
`,
456+
"src/root.tsx": js`
457+
import {
458+
Meta,
459+
Links,
460+
Outlet,
461+
Routes,
462+
Route,
463+
Scripts,
464+
ScrollRestoration,
465+
} from "@remix-run/react";
466+
467+
export function Layout({ children }: { children: React.ReactNode }) {
468+
return (
469+
<html>
470+
<head>
471+
<Meta />
472+
<Links />
473+
</head>
474+
<body>
475+
{children}
476+
<ScrollRestoration />
477+
<Scripts />
478+
</body>
479+
</html>
480+
);
481+
}
482+
483+
export default function Root() {
484+
return (
485+
<>
486+
<h1 data-root>Root</h1>
487+
<Routes>
488+
<Route path="/" element={<h2 data-index>Index</h2>} />
489+
</Routes>
490+
</>
491+
);
492+
}
493+
494+
export function HydrateFallback() {
495+
return <h1 data-loading>Loading SPA...</h1>;
496+
}
497+
`,
498+
},
499+
});
500+
appFixture = await createAppFixture(fixture);
501+
502+
let res = await fixture.requestDocument("/");
503+
let html = await res.text();
504+
expect(html).toMatch('<h1 data-loading="true">Loading SPA...</h1>');
505+
506+
let logs: string[] = [];
507+
page.on("console", (msg) => logs.push(msg.text()));
508+
509+
let app = new PlaywrightFixture(appFixture, page);
510+
await app.goto("/");
511+
await page.waitForSelector("[data-root]");
512+
expect(await page.locator("[data-root]").textContent()).toBe("Root");
513+
expect(await page.locator("[data-index]").textContent()).toBe("Index");
514+
515+
// Hydrates without issues
516+
expect(logs).toEqual([]);
517+
});
434518
});
435519

436520
test.describe("normal apps", () => {

0 commit comments

Comments
 (0)