Skip to content

Commit 6ded334

Browse files
committed
rename hook to processRequestError
1 parent 7b0dd6a commit 6ded334

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

packages/remix-dev/vite/plugin.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,9 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
669669
setTimeout(showUnstableWarning, 50);
670670
});
671671

672-
// Give the request handler access to the critical CSS in dev to avoid a
673-
// flash of unstyled content since Vite injects CSS file contents via JS
674672
setDevServerHooks({
673+
// Give the request handler access to the critical CSS in dev to avoid a
674+
// flash of unstyled content since Vite injects CSS file contents via JS
675675
getCriticalCss: async (build, url) => {
676676
invariant(cachedPluginConfig);
677677
return getStylesForUrl(
@@ -682,7 +682,13 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => {
682682
url
683683
);
684684
},
685-
fixStacktrace: vite.ssrFixStacktrace,
685+
// If an error is caught within the request handler, let Vite fix the
686+
// stack trace so it maps back to the actual source code
687+
processRequestError: (error) => {
688+
if (error instanceof Error) {
689+
vite.ssrFixStacktrace(error);
690+
}
691+
},
686692
});
687693

688694
// We cache the pluginConfig here to make sure we're only invalidating virtual modules when necessary.

packages/remix-server-runtime/dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export function logDevReady(build: ServerBuild) {
2727
}
2828

2929
type DevServerHooks = {
30-
getCriticalCss: (
30+
getCriticalCss?: (
3131
build: ServerBuild,
3232
pathname: string
3333
) => Promise<string | undefined>;
34-
fixStacktrace: (error: Error) => void;
34+
processRequestError?: (error: unknown) => void;
3535
};
3636

3737
const globalDevServerHooksKey = "__remix_devServerHooks";

packages/remix-server-runtime/server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ export const createRequestHandler: CreateRequestHandlerFunction = (
9595

9696
let matches = matchServerRoutes(routes, url.pathname);
9797
let handleError = (error: unknown) => {
98-
let devServerHooks = getDevServerHooks();
99-
if (devServerHooks && error instanceof Error) {
100-
devServerHooks.fixStacktrace(error);
98+
if (mode === ServerMode.Development) {
99+
getDevServerHooks()?.processRequestError?.(error);
101100
}
101+
102102
errorHandler(error, {
103103
context: loadContext,
104104
params: matches && matches.length > 0 ? matches[0].params : {},
@@ -142,7 +142,7 @@ export const createRequestHandler: CreateRequestHandlerFunction = (
142142
} else {
143143
let criticalCss =
144144
mode === ServerMode.Development
145-
? await getDevServerHooks()?.getCriticalCss(_build, url.pathname)
145+
? await getDevServerHooks()?.getCriticalCss?.(_build, url.pathname)
146146
: undefined;
147147

148148
response = await handleDocumentRequestRR(

0 commit comments

Comments
 (0)