From a543220773bb5ec88a09a2cb754022852c0eb1b1 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 11 May 2022 10:26:02 -0600 Subject: [PATCH] fix: Remove ssrError when invalidating a module (#8124) --- .../node/server/__tests__/moduleGraph.spec.ts | 22 +++++++++++++++++++ packages/vite/src/node/server/moduleGraph.ts | 1 + 2 files changed, 23 insertions(+) create mode 100644 packages/vite/src/node/server/__tests__/moduleGraph.spec.ts diff --git a/packages/vite/src/node/server/__tests__/moduleGraph.spec.ts b/packages/vite/src/node/server/__tests__/moduleGraph.spec.ts new file mode 100644 index 00000000000000..afaea5c151e949 --- /dev/null +++ b/packages/vite/src/node/server/__tests__/moduleGraph.spec.ts @@ -0,0 +1,22 @@ +import { beforeEach, describe, expect, it } from 'vitest' +import { ModuleGraph } from '../moduleGraph' +let moduleGraph: ModuleGraph + +describe('moduleGraph', () => { + describe('invalidateModule', () => { + beforeEach(() => { + moduleGraph = new ModuleGraph((id) => Promise.resolve({ id })) + }) + + it('removes an ssrError', async () => { + const entryUrl = '/x.js' + + const entryModule = await moduleGraph.ensureEntryFromUrl(entryUrl, false) + entryModule.ssrError = new Error(`unable to execute module`) + + expect(entryModule.ssrError).to.be.a('error') + moduleGraph.invalidateModule(entryModule) + expect(entryModule.ssrError).toBe(null) + }) + }) +}) diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index 5730f4be324744..4c98b83a7e74ca 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -55,6 +55,7 @@ function invalidateSSRModule(mod: ModuleNode, seen: Set) { } seen.add(mod) mod.ssrModule = null + mod.ssrError = null mod.importers.forEach((importer) => invalidateSSRModule(importer, seen)) }