diff --git a/packages/qwik/src/optimizer/src/plugins/plugin.ts b/packages/qwik/src/optimizer/src/plugins/plugin.ts index 804af0e3ee6..c17d069f0ce 100644 --- a/packages/qwik/src/optimizer/src/plugins/plugin.ts +++ b/packages/qwik/src/optimizer/src/plugins/plugin.ts @@ -517,14 +517,20 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) { const match = /^(.*\.[mc]?[jt]sx?)_([^/]+)_([^_]+)\.js($|\?)/.exec(pathId); if (match) { const [, parentId, name, hash] = match; - debug(`resolveId(${count})`, `resolved to QRL ${name}_${hash} of ${parentId}`); - // Save for quick lookup - knownQrls.set(hash, parentId); - result = { - id: pathId + parsedId.query, - // QRL segments can't have side effects. Probably never useful, but it's here for consistency - moduleSideEffects: false, - }; + return ctx.resolve(parentId, importerId, { skipSelf: true }).then((resolved) => { + if (resolved) { + debug(`resolveId(${count})`, `resolved to QRL ${name}_${hash} of ${parentId}`); + // Save for quick lookup + knownQrls.set(hash, resolved.id); + return { + id: pathId + parsedId.query, + // QRL segments can't have side effects. Probably never useful, but it's here for consistency + moduleSideEffects: false, + }; + } else { + debug(`resolveId(${count})`, `${parentId} does not exist`); + } + }); } else if (importerId) { /** * When we get here it's neither a virtual module nor a QRL segment. However, Rollup can ask @@ -861,7 +867,7 @@ export const manifest = ${JSON.stringify(manifest)};\n`; for (const outputs of [clientTransformedOutputs, serverTransformedOutputs]) { for (const [key, [_, parentId]] of outputs) { if (parentId === id) { - debug('handleHotUpdate()', `invalidate segment ${key}`); + debug('handleHotUpdate()', `invalidate ${id} segment ${key}`); outputs.delete(key); const mod = ctx.server.moduleGraph.getModuleById(key); if (mod) { diff --git a/packages/qwik/src/optimizer/src/plugins/plugin.unit.ts b/packages/qwik/src/optimizer/src/plugins/plugin.unit.ts index 60e39d913b1..1547bbb06fe 100644 --- a/packages/qwik/src/optimizer/src/plugins/plugin.unit.ts +++ b/packages/qwik/src/optimizer/src/plugins/plugin.unit.ts @@ -222,43 +222,51 @@ describe('resolveId', () => { test('qrls', async () => { const plugin = await mockPlugin(); expect(plugin.resolveId(null!, 'foo', undefined)).toBeFalsy(); - expect( + const ctx = { resolve: async () => ({ id: 'Yey' }) } as any; + await expect( plugin.resolveId( - null!, + ctx, '/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js', undefined ) - ).toHaveProperty('id', '/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js'); + ).resolves.toHaveProperty( + 'id', + '/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js' + ); expect( - plugin.resolveId(null!, '/root/src/routes/layout.tsx_s_7xk04rim0vu.js', undefined) + await plugin.resolveId(ctx, '/root/src/routes/layout.tsx_s_7xk04rim0vu.js', undefined) ).toHaveProperty('id', '/root/src/routes/layout.tsx_s_7xk04rim0vu.js'); expect(plugin.resolveId(null!, './foo', '/root/src/routes/layout.tsx')).toBeFalsy(); expect( - plugin.resolveId( - null!, + await plugin.resolveId( + ctx, './layout.tsx_layout_component_usetask_1_7xk04rim0vu.js', '/root/src/routes/layout.tsx' ) ).toHaveProperty('id', '/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js'); // this uses the already populated id we created above expect( - plugin.resolveId( + await plugin.resolveId( { resolve: (id: string, importer: string) => { expect(id).toBe('/root/src/routes/foo'); - expect(importer).toBe('/root/src/routes/layout.tsx'); - return 'hi'; + expect(importer).toBe('Yey'); + return { id: 'hi' }; }, } as any, './foo', '/root/src/routes/layout.tsx_layout_component_usetask_1_7xk04rim0vu.js' ) - ).toBe('hi'); + ).toEqual({ id: 'hi' }); }); test('win32', async () => { const plugin = await mockPlugin('win32'); expect( - plugin.resolveId(null!, 'C:\\src\\routes\\layout.tsx_s_7xk04rim0vu.js', undefined) + await plugin.resolveId( + { resolve: async () => 'Yey' } as any, + 'C:\\src\\routes\\layout.tsx_s_7xk04rim0vu.js', + undefined + ) ).toHaveProperty('id', 'C:/src/routes/layout.tsx_s_7xk04rim0vu.js'); }); test('libs', async () => {