Skip to content

Commit

Permalink
fix: reuse mod.ssrError
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored and TrickyPi committed Mar 7, 2022
1 parent 2e5a438 commit 458c4c5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/vite/src/node/server/moduleGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class ModuleNode {
transformResult: TransformResult | null = null
ssrTransformResult: TransformResult | null = null
ssrModule: Record<string, any> | null = null
ssrError: Error | null = null
lastHMRTimestamp = 0

constructor(url: string) {
Expand Down
4 changes: 1 addition & 3 deletions packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ test('always throw error when evaluating an wrong SSR module', async () => {
}
await viteServer.close()
expect(expectedErrors).toHaveLength(2)
expectedErrors.forEach((error) => {
expect(error?.message).toContain(THROW_MESSAGE)
})
expect(expectedErrors[0]).toBe(expectedErrors[1])
expect(spy).toBeCalledTimes(2)
spy.mock.calls.forEach(([info]) => {
expect(info).toContain('Error when evaluating SSR module')
Expand Down
6 changes: 5 additions & 1 deletion packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ async function instantiateModule(
const { moduleGraph } = server
const mod = await moduleGraph.ensureEntryFromUrl(url, true)

if (mod.ssrError) {
throw mod.ssrError
}

if (mod.ssrModule) {
return mod.ssrModule
}
Expand Down Expand Up @@ -202,7 +206,7 @@ async function instantiateModule(
ssrExportAll
)
} catch (e) {
mod.ssrModule = null
mod.ssrError = e
if (e.stack && fixStacktrace !== false) {
const stacktrace = ssrRewriteStacktrace(e.stack, moduleGraph)
rebindErrorStacktrace(e, stacktrace)
Expand Down

0 comments on commit 458c4c5

Please sign in to comment.