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/salty-breads-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react-webpack-plugin": patch
---

Fix issue with lazy loading of bundles when source maps are enabled.
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ class ReactWebpackPlugin {
const exports = module.exports
`,
old,
`\
return module.exports
`
;return module.exports
})`,
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function bar() {
return import('./baz.js').then(({ baz }) => {
return `bar ${baz()}`;
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function baz() {
return 'baz';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export async function foo() {
const { bar } = await import('./bar.js');
return 'foo ' + await bar();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/// <reference types="vitest/globals" />

import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';

const importPromise = import('./foo.js');

it('should have module.exports in foo.js template', async () => {
const { foo } = await importPromise;
await expect(foo()).resolves.toBe(`foo bar baz`);

const tasmJSON = JSON.parse(
await readFile(
resolve(__dirname, '.rspeedy/async/foo.js/tasm.json'),
'utf-8',
),
);

const ret = eval(tasmJSON.lepusCode.root);

expect(typeof ret).toBe('function');

const exports = ret();

expect(exports).toHaveProperty('ids', [
'./foo.js-react:main-thread',
]);

expect(exports).toHaveProperty('modules', {
'(react:main-thread)/./foo.js': expect.any(Function),
});
});

it('should have module.exports in bar.js template', async () => {
const tasmJSON = JSON.parse(
await readFile(
resolve(__dirname, '.rspeedy/async/bar.js/tasm.json'),
'utf-8',
),
);

const ret = eval(tasmJSON.lepusCode.root);

expect(typeof ret).toBe('function');

const exports = ret();

expect(exports).toHaveProperty('ids', [
'./bar.js-react:main-thread',
]);

expect(exports).toHaveProperty('modules', {
'(react:main-thread)/./bar.js': expect.any(Function),
});
});

it('should have module.exports in baz.js template', async () => {
const tasmJSON = JSON.parse(
await readFile(
resolve(__dirname, '.rspeedy/async/baz.js/tasm.json'),
'utf-8',
),
);

const ret = eval(tasmJSON.lepusCode.root);

expect(typeof ret).toBe('function');

const exports = ret();

expect(exports).toHaveProperty('ids', [
'./baz.js-react:main-thread',
]);

expect(exports).toHaveProperty('modules', {
'(react:main-thread)/./baz.js': expect.any(Function),
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
LynxEncodePlugin,
LynxTemplatePlugin,
} from '@lynx-js/template-webpack-plugin';

import { createConfig } from '../../../create-react-config.js';

const config = createConfig();

/** @type {import('@rspack/core').Configuration} */
export default {
context: __dirname,
...config,
devtool: 'source-map',
output: {
...config.output,
chunkFilename: '.rspeedy/async/[name].js',
},
plugins: [
...config.plugins,
new LynxEncodePlugin(),
new LynxTemplatePlugin({
...LynxTemplatePlugin.defaultOptions,
chunks: ['main:main-thread', 'main:background'],
filename: 'main/template.js',
intermediate: '.rspeedy/main',
}),
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import("@lynx-js/test-tools").TConfigCaseConfig} */
module.exports = {
bundlePath: [
// We do not run main-thread.js since the async chunk has been modified.
// 'main:main-thread.js',
'main:background.js',
],
};
Loading