Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-tigers-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react-webpack-plugin": patch
---

Fix issue where loading a lazy bundle fails if it does not return a webpack chunk.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function createLynxProcessEvalResultRuntimeModule(

return `
${LynxRuntimeGlobals.lynxProcessEvalResult} = function (result, schema) {
var chunk = result(schema);
if (chunk.ids && chunk.modules) {
var chunk = result && result(schema);
if (chunk && chunk.ids && chunk.modules) {
// We only deal with webpack chunk
${webpack.RuntimeGlobals.externalInstallChunk}(chunk);
// TODO: sort with preOrderIndex. See: https://github.com/web-infra-dev/rspack/pull/8588
Expand All @@ -37,6 +37,7 @@ ${LynxRuntimeGlobals.lynxProcessEvalResult} = function (result, schema) {
}
return chunk;
}
return chunk
}
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,63 @@ it('should have processEvalResult', async () => {
}
});

it('should allow result to be null', () => {
if (!__LEPUS__) {
return;
}

const ret = globalThis.processEvalResult(null, 'foo');
expect(ret).toBeNull();
});

it('should allow result to be undefined', () => {
if (!__LEPUS__) {
return;
}

const ret = globalThis.processEvalResult(undefined, 'foo');
expect(ret).toBeUndefined();
});

it('should allow result to return non-webpack chunk', () => {
if (!__LEPUS__) {
return;
}

const result = {};
const fn = vi.fn();
fn.mockReturnValue(result);

const ret = globalThis.processEvalResult(fn, 'foo');
expect(fn).toHaveBeenCalledWith('foo');
expect(ret).toBe(result);
});

it('should allow result to return webpack chunk', () => {
if (!__LEPUS__) {
return;
}

const result = {
ids: ['foo'],
modules: {
foo: vi.fn(),
},
};
const fn = vi.fn();
fn.mockReturnValue(result);

__webpack_require__.C = (chunk) => {
__webpack_modules__['foo'] = chunk.modules.foo;
expect(chunk).toBe(result);
};

const ret = globalThis.processEvalResult(fn, 'foo');
expect(fn).toHaveBeenCalledWith('foo');
expect(ret).toBe(result);
expect(result.modules.foo).toHaveBeenCalled();
});

it('should have async chunks', () => {
const LAYER = __LEPUS__ ? 'react:main-thread' : 'react:background';

Expand Down
Loading