Skip to content

Commit

Permalink
do not use built-in, minimal SSR in middleware mode (#7763)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Oct 25, 2023
1 parent 74581e0 commit b8209fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions integration/vite-dev-express-test.ts
Expand Up @@ -65,6 +65,7 @@ test.beforeAll(async () => {
build: vite
? () => unstable_loadViteServerBuild(vite)
: await import("./build/index.js"),
getLoadContext: () => ({ value: "context" }),
})
);
Expand Down Expand Up @@ -162,18 +163,19 @@ test("Vite custom server HMR & HDR", async ({ page }) => {
)
.replace(
"// loader",
`// loader\nexport const loader = () => json({ message: "HDR updated: 0" });`
`// loader\nexport const loader = ({ context }) => json({ message: "HDR updated: 0", context });`
)
.replace(
"// hooks",
"// hooks\nconst { message } = useLoaderData<typeof loader>();"
"// hooks\nconst { message, context } = useLoaderData<typeof loader>();"
)
.replace(
"{/* elements */}",
`{/* elements */}\n<p data-hdr>{message}</p>`
`{/* elements */}\n<p data-context>{context.value}</p>\n<p data-hdr>{message}</p>`
)
);
await page.waitForLoadState("networkidle");
await expect(page.locator("#index [data-context]")).toHaveText("context");
let hdrStatus = page.locator("#index [data-hdr]");
await expect(hdrStatus).toHaveText("HDR updated: 0");
// React Fast Refresh cannot preserve state for a component when hooks are added or removed
Expand Down Expand Up @@ -252,8 +254,8 @@ test("Vite custom server HMR & HDR", async ({ page }) => {
`// imports\nimport { direct } from "../direct-hdr-dep"`
)
.replace(
`json({ message: "HDR updated: 2" })`,
`json({ message: "HDR updated: " + direct })`
`json({ message: "HDR updated: 2", context })`,
`json({ message: "HDR updated: " + direct, context })`
)
);
await page.waitForLoadState("networkidle");
Expand Down
2 changes: 2 additions & 0 deletions packages/remix-dev/vite/plugin.ts
Expand Up @@ -520,6 +520,8 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
vite.httpServer?.on("listening", () => {
setTimeout(showUnstableWarning, 50);
});
// Let user servers handle SSR requests in middleware mode
if (vite.config.server.middlewareMode) return;
return () => {
vite.middlewares.use(async (req, res, next) => {
try {
Expand Down

0 comments on commit b8209fc

Please sign in to comment.