@@ -20,7 +20,7 @@ import type {
20
20
21
21
function wrapExpressRequestHandler (
22
22
origRequestHandler : ExpressRequestHandler ,
23
- build : ServerBuild | Promise < ServerBuild > | ( ( ) => Promise < ServerBuild > | ServerBuild ) ,
23
+ build : ServerBuild | ( ( ) => Promise < ServerBuild > | ServerBuild ) ,
24
24
) : ExpressRequestHandler {
25
25
let routes : ServerRoute [ ] ;
26
26
@@ -52,20 +52,14 @@ function wrapExpressRequestHandler(
52
52
const url = new URL ( request . url ) ;
53
53
54
54
// This is only meant to be used on development servers, so we don't need to worry about performance here
55
- if ( ! routes ) {
56
- if ( build instanceof Promise ) {
57
- const resolvedBuild = await build ;
58
- routes = createRoutes ( resolvedBuild . routes ) ;
59
- }
55
+ if ( ! routes && typeof build === 'function' ) {
56
+ const resolvedBuild = build ( ) ;
60
57
61
- if ( typeof build === 'function' ) {
62
- const resolvedBuild = build ( ) ;
63
- if ( resolvedBuild instanceof Promise ) {
64
- const resolved = await resolvedBuild ;
65
- routes = createRoutes ( resolved . routes ) ;
66
- } else {
67
- routes = createRoutes ( resolvedBuild . routes ) ;
68
- }
58
+ if ( resolvedBuild instanceof Promise ) {
59
+ const resolved = await resolvedBuild ;
60
+ routes = createRoutes ( resolved . routes ) ;
61
+ } else {
62
+ routes = createRoutes ( resolvedBuild . routes ) ;
69
63
}
70
64
}
71
65
@@ -98,16 +92,12 @@ function wrapGetLoadContext(origGetLoadContext: () => AppLoadContext): GetLoadCo
98
92
// A wrapper around build if it's a Promise or a function that returns a Promise that calls instrumentServer on the resolved value
99
93
// This is currently only required for Vite development mode with HMR
100
94
function wrapBuild (
101
- build : ServerBuild | Promise < ServerBuild > | ( ( ) => Promise < ServerBuild > | ServerBuild ) ,
102
- ) : ServerBuild | Promise < ServerBuild > {
103
- if ( build instanceof Promise ) {
104
- return build . then ( resolved => instrumentBuild ( resolved , true ) ) ;
105
- }
106
-
95
+ build : ServerBuild | ( ( ) => Promise < ServerBuild > | ServerBuild ) ,
96
+ ) : ServerBuild | ( ( ) => Promise < ServerBuild > | ServerBuild ) {
107
97
if ( typeof build === 'function' ) {
108
98
const resolved = build ( ) ;
109
99
if ( resolved instanceof Promise ) {
110
- return resolved . then ( resolved => instrumentBuild ( resolved , true ) ) ;
100
+ return ( ) => resolved . then ( resolved => instrumentBuild ( resolved , true ) ) ;
111
101
}
112
102
113
103
return instrumentBuild ( resolved , true ) ;
0 commit comments