-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(remix-dev/vite, server-runtime): pass Vite server errors to vite.ssrFixStacktrace
#8066
Changes from all commits
1396b16
5988807
25e865c
9b7b08f
4eb7194
22eae1a
cc9d5f9
6708f3e
16022e4
7b0dd6a
6ded334
09dcf0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@remix-run/dev": patch | ||
"@remix-run/server-runtime": patch | ||
--- | ||
|
||
Pass request handler errors to `vite.ssrFixStacktrace` in Vite dev to ensure stack traces correctly map to the original source code |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,9 +669,9 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => { | |
setTimeout(showUnstableWarning, 50); | ||
}); | ||
|
||
// Give the request handler access to the critical CSS in dev to avoid a | ||
// flash of unstyled content since Vite injects CSS file contents via JS | ||
setDevServerHooks({ | ||
// Give the request handler access to the critical CSS in dev to avoid a | ||
// flash of unstyled content since Vite injects CSS file contents via JS | ||
getCriticalCss: async (build, url) => { | ||
invariant(cachedPluginConfig); | ||
return getStylesForUrl( | ||
|
@@ -682,6 +682,13 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => { | |
url | ||
); | ||
}, | ||
// If an error is caught within the request handler, let Vite fix the | ||
// stack trace so it maps back to the actual source code | ||
processRequestError: (error) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heads up that I've renamed this hook from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't usually have a strong opinion (and good sense) on naming things, so please feel free and don't hesitate to tweak anything I named.
That sounds like a huge plan! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't see any need for these specific hooks to be used outside of Vite. For now it's mainly just to avoid the weirdness of having references to Vite in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am getting errors such as:
and I am wondering if related to these changes. |
||
if (error instanceof Error) { | ||
vite.ssrFixStacktrace(error); | ||
} | ||
}, | ||
}); | ||
|
||
// We cache the pluginConfig here to make sure we're only invalidating virtual modules when necessary. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,12 +94,17 @@ export const createRequestHandler: CreateRequestHandlerFunction = ( | |
let url = new URL(request.url); | ||
|
||
let matches = matchServerRoutes(routes, url.pathname); | ||
let handleError = (error: unknown) => | ||
let handleError = (error: unknown) => { | ||
if (mode === ServerMode.Development) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this check because we want to make sure these hooks are never called outside of dev, especially since the hooks are coming from a global that can be modified by anyone. |
||
getDevServerHooks()?.processRequestError?.(error); | ||
} | ||
|
||
errorHandler(error, { | ||
context: loadContext, | ||
params: matches && matches.length > 0 ? matches[0].params : {}, | ||
request, | ||
}); | ||
}; | ||
|
||
let response: Response; | ||
if (url.searchParams.has("_data")) { | ||
|
@@ -137,7 +142,7 @@ export const createRequestHandler: CreateRequestHandlerFunction = ( | |
} else { | ||
let criticalCss = | ||
mode === ServerMode.Development | ||
? await getDevServerHooks()?.getCriticalCss(_build, url.pathname) | ||
? await getDevServerHooks()?.getCriticalCss?.(_build, url.pathname) | ||
: undefined; | ||
|
||
response = await handleDocumentRequestRR( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really nice 👍