Skip to content

Commit

Permalink
Always prepend DOCTYPE in SPA mode entry.server.tsx (#8725)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Feb 9, 2024
1 parent 30544ed commit f7983ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 48 deletions.
48 changes: 3 additions & 45 deletions integration/spa-mode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ test.describe("SPA Mode", () => {
});
});

test("prepends DOCTYPE to <html> documents if not present", async () => {
test("prepends DOCTYPE to HTML in the default entry.server.tsx", async () => {
let fixture = await createFixture({
compiler: "vite",
spaMode: true,
Expand Down Expand Up @@ -222,48 +222,6 @@ test.describe("SPA Mode", () => {
expect(await res.text()).toMatch(/^<!DOCTYPE html>\n<html lang="en">/);
});

test("does not prepend DOCTYPE if user is not hydrating the document", async () => {
let fixture = await createFixture({
compiler: "vite",
spaMode: true,
files: {
"vite.config.ts": js`
import { defineConfig } from "vite";
import { vitePlugin as remix } from "@remix-run/dev";
export default defineConfig({
plugins: [remix({ ssr: false })],
});
`,
"app/root.tsx": js`
import { Outlet, Scripts } from "@remix-run/react";
export default function Root() {
return (
<div>
<h1 data-root>Root</h1>
<Scripts />
</div>
);
}
export function HydrateFallback() {
return (
<div>
<h1>Loading SPA...</h1>
<Scripts />
</div>
);
}
`,
},
});
let res = await fixture.requestDocument("/");
let html = await res.text();
expect(html).toMatch(/^<div>/);
expect(html).not.toMatch(/<!DOCTYPE html>/);
});

test("works when combined with a basename", async ({ page }) => {
fixture = await createFixture({
compiler: "vite",
Expand Down Expand Up @@ -363,7 +321,7 @@ test.describe("SPA Mode", () => {
<title>Not from Remix!</title>
</head>
<body>
<div id="app"><!-- Remix-SPA--></div>
<div id="app"><!-- Remix SPA --></div>
</body>
</html>
`,
Expand Down Expand Up @@ -406,7 +364,7 @@ test.describe("SPA Mode", () => {
);
const html = shellHtml.replace(
"<!-- Remix-SPA-->",
"<!-- Remix SPA -->",
appHtml
);
Expand Down
4 changes: 1 addition & 3 deletions packages/remix-dev/config/defaults/entry.server.spa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export default function handleRequest(
let html = renderToString(
<RemixServer context={remixContext} url={request.url} />
);
if (html.startsWith("<html")) {
html = "<!DOCTYPE html>\n" + html;
}
html = "<!DOCTYPE html>\n" + html;
return new Response(html, {
headers: { "Content-Type": "text/html" },
status: responseStatusCode,
Expand Down

0 comments on commit f7983ad

Please sign in to comment.