File tree Expand file tree Collapse file tree 3 files changed +15
-9
lines changed
Expand file tree Collapse file tree 3 files changed +15
-9
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff line change @@ -27,11 +27,11 @@ export function logDevReady(build: ServerBuild) {
2727}
2828
2929type 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
3737const globalDevServerHooksKey = "__remix_devServerHooks" ;
Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments