Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/plugin-vite/src/plugins/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export function deno(): Plugin {
platform: "browser",
preserveJsx: true,
cachedOnly: true,
})
.createLoader();
}).createLoader();
},
applyToEnvironment() {
return true;
Expand Down
25 changes: 20 additions & 5 deletions packages/plugin-vite/src/plugins/dev_server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import type { DevEnvironment, Plugin } from "vite";
import {
type DevEnvironment,
isRunnableDevEnvironment,
type Plugin,
} from "vite";
import * as path from "@std/path";
import { ASSET_CACHE_BUST_KEY } from "fresh/internal";
import { createRequest, sendResponse } from "@remix-run/node-fetch-server";
import { hashCode } from "../shared.ts";

interface FetchHandler {
default: {
fetch: (req: Request) => Promise<Response>;
};
setErrorInterceptor?: (fn: (err: unknown) => void) => void;
}

export function devServer(): Plugin[] {
let publicDir = "";
return [
Expand Down Expand Up @@ -79,16 +90,20 @@ export function devServer(): Plugin[] {
// Ignore
}

if (!isRunnableDevEnvironment(server.environments.ssr)) return;

try {
const mod = await server.ssrLoadModule("fresh:server_entry");
const req = createRequest(nodeReq, nodeRes);
mod.setErrorInterceptor((err: unknown) => {
const mod = await server.environments.ssr.runner.import<unknown>(
"fresh:server_entry",
) as FetchHandler;
mod.setErrorInterceptor?.((err: unknown) => {
if (err instanceof Error) {
server.ssrFixStacktrace(err);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works to fix it, then that's great, but in theory it shouldn't be needed 🤔

server.ssrFixStacktrace and server.ssrRewriteStacktrace do not have to be called when using the Module Runner APIs. The stack traces will be updated unless sourcemapInterceptor is set to false. — SSR Using ModuleRunner API

I assumed it was because sourcemapInterceptor was indeed false because Deno had nooped process.setSourceMapsEnabled, but fixing that didn't seem to fix it.

Relevant Vite code: https://github.com/vitejs/vite/blob/99897d27b44dd73307fa03e2f11f0baa1a1dc939/packages/vite/src/node/ssr/runtime/serverModuleRunner.ts#L58-L72

}
});

const res = (await mod.default.fetch(req)) as Response;
const req = createRequest(nodeReq, nodeRes);
const res = await mod.default.fetch(req);

// Collect css eagerly to avoid FOUC. This is a workaround for
// Vite not supporting css natively. It's a bit hacky, but
Expand Down
Loading