diff --git a/frontend/__tests__/version-check.test.ts b/frontend/__tests__/version-check.test.ts index 6c60507b..d1eae514 100644 --- a/frontend/__tests__/version-check.test.ts +++ b/frontend/__tests__/version-check.test.ts @@ -1,7 +1,47 @@ /** * @jest-environment jsdom */ -import { isStale, hardReload, __resetForTest, __setBuildShaForTest } from '@/lib/version-check' +import { + isStale, + hardReload, + isChunkLoadError, + __resetForTest, + __setBuildShaForTest, +} from '@/lib/version-check' + +describe('version-check.isChunkLoadError', () => { + it('matches webpack ChunkLoadError by name', () => { + const e = new Error('boom') + e.name = 'ChunkLoadError' + expect(isChunkLoadError(e)).toBe(true) + }) + + it('matches webpack "Loading chunk failed" message', () => { + expect(isChunkLoadError(new Error('Loading chunk 429 failed'))).toBe(true) + }) + + it.each([ + // Turbopack (Next.js 16 default) — a plain Error, no ChunkLoadError name. + 'Failed to load chunk /_next/static/chunks/e66613528f386db8.js from module 64893', + 'Failed to load chunk /_next/static/chunks/abc.js as a runtime dependency of chunk 12', + 'Failed to load chunk /_next/static/chunks/abc.js from an HMR update', + ])('matches Turbopack chunk-load message: %s', (msg) => { + expect(isChunkLoadError(new Error(msg))).toBe(true) + }) + + it('matches native ESM dynamic-import failures', () => { + expect( + isChunkLoadError(new Error('Failed to fetch dynamically imported module: https://x/y.js')), + ).toBe(true) + expect(isChunkLoadError(new Error('Importing a module script failed.'))).toBe(true) + }) + + it('ignores unrelated errors and falsy input', () => { + expect(isChunkLoadError(new Error('Cannot read properties of undefined'))).toBe(false) + expect(isChunkLoadError(null)).toBe(false) + expect(isChunkLoadError(undefined)).toBe(false) + }) +}) describe('version-check.isStale', () => { const fetchMock = jest.fn() diff --git a/frontend/lib/version-check.ts b/frontend/lib/version-check.ts index 958ad1a2..b7ec2f7f 100644 --- a/frontend/lib/version-check.ts +++ b/frontend/lib/version-check.ts @@ -112,8 +112,15 @@ export function hardReload(latestSha?: string): boolean { /** * Returns true if `err` looks like a chunk-load error from a post-deploy - * mismatch. Next.js surfaces these as `ChunkLoadError` or messages mentioning - * "Loading chunk" / "dynamically imported module". + * mismatch. Bundlers surface these differently: + * + * - webpack: `ChunkLoadError` / "Loading chunk failed" + * - native ESM: "Failed to fetch dynamically imported module" / + * "Importing a module script failed" + * - Turbopack (Next.js 16 default): a plain `Error` whose message is + * "Failed to load chunk from module " (also "… as a runtime + * dependency of chunk " / "… from an HMR update"). These carry NO + * `ChunkLoadError` name, so they must be matched by message. */ export function isChunkLoadError(err: unknown): boolean { if (!err) return false @@ -123,6 +130,7 @@ export function isChunkLoadError(err: unknown): boolean { return ( /ChunkLoadError/i.test(msg) || /Loading chunk [\w-]+ failed/i.test(msg) || + /Failed to load chunk/i.test(msg) || /Failed to fetch dynamically imported module/i.test(msg) || /Importing a module script failed/i.test(msg) ) diff --git a/pyproject.toml b/pyproject.toml index df0e60f3..1dd4aece 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "karaoke-gen" -version = "0.191.1" +version = "0.191.2" description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens." authors = ["Andrew Beveridge "] license = "MIT"