Skip to content

feat: use modulerunner for ssr#3645

Open
lishaduck wants to merge 4 commits into
freshframework:mainfrom
lishaduck:envapi2
Open

feat: use modulerunner for ssr#3645
lishaduck wants to merge 4 commits into
freshframework:mainfrom
lishaduck:envapi2

Conversation

@lishaduck
Copy link
Copy Markdown
Contributor

Extracted from/stacked upon #3634.

bartlomieju and others added 3 commits March 25, 2026 19:13
The switch from ssrLoadModule to ModuleRunner removed stack trace
source mapping. Re-add setErrorInterceptor call so errors in route
handlers get source-mapped before the error overlay renders them,
and ssrFixStacktrace in the outer catch for module loading errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
) 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

@lishaduck lishaduck changed the title Use ModuleRunner for SSR feat: use modulerunner for ssr Mar 29, 2026
Copy link
Copy Markdown
Contributor

@fibibot fibibot left a comment

Choose a reason for hiding this comment

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

Direction matches the rest of the env-API migration from #3634ssrLoadModule is the old shim for the SSR env.

One concern: if (!isRunnableDevEnvironment(server.environments.ssr)) return; exits the middleware without calling next() or writing a response — if the SSR env is ever non-runnable, the request hangs. For Fresh's default config this branch is unreachable, but it's a sharp edge; either fall through to next() or assert with a thrown error so failures are loud.

Holding approval until CI is green — pr-title is red because the workflow ran with the original title "Use ModuleRunner for SSR" before the lowercase rename. An empty push or rebase should re-trigger and clear it.

  • nit: the hand-rolled FetchHandler types setErrorInterceptor? optional, forcing ?. at the call site. server_entry.ts always exports it — making the field required would surface a real regression if that export ever changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants