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/shy-pears-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/rspeedy": patch
---

Use `chunkLoading: 'import-scripts'` for Web platform
33 changes: 24 additions & 9 deletions packages/rspeedy/core/src/plugins/chunkLoading.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ import type { RsbuildPlugin } from '@rsbuild/core'

import { ChunkLoadingWebpackPlugin } from '@lynx-js/chunk-loading-webpack-plugin'

import { isLynx } from '../utils/is-lynx.js'
import { isWeb } from '../utils/is-web.js'

export function pluginChunkLoading(): RsbuildPlugin {
return {
name: 'lynx:rsbuild:chunk-loading',
setup(api) {
api.modifyBundlerChain(chain => {
// dprint-ignore
chain
api.modifyBundlerChain((chain, { environment }) => {
if (isWeb(environment)) {
chain
.output
.chunkLoading('import-scripts')
.end()
return
}

if (isLynx(environment)) {
// dprint-ignore
chain
.plugin('lynx:chunk-loading')
.use(ChunkLoadingWebpackPlugin)
.end()
Expand All @@ -23,14 +35,17 @@ export function pluginChunkLoading(): RsbuildPlugin {
.chunkFormat('commonjs')
.iife(false)
.end()
}
})

api.modifyWebpackChain(chain => {
chain
.output
// For webpack, we directly use `chunkLoading: 'lynx'`.
.chunkLoading('lynx')
.end()
api.modifyWebpackChain((chain, { environment }) => {
if (isLynx(environment)) {
chain
.output
// For webpack, we directly use `chunkLoading: 'lynx'`.
.chunkLoading('lynx')
.end()
}
})
},
}
Expand Down
13 changes: 11 additions & 2 deletions packages/rspeedy/core/src/plugins/target.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
import type { RsbuildPlugin } from '@rsbuild/core'

import { getESVersionTarget } from '../utils/getESVersionTarget.js'
import { isWeb } from '../utils/is-web.js'

export function pluginTarget(): RsbuildPlugin {
return {
name: 'lynx:rsbuild:target',
setup(api) {
api.modifyBundlerChain((options) => {
options.target([getESVersionTarget()])
api.modifyBundlerChain((options, { environment }) => {
if (isWeb(environment)) {
options.target([
getESVersionTarget(),
// Add `target: 'web'` to make Rsbuild inject HMR related code.
'web',
Comment thread
colinaaa marked this conversation as resolved.
])
} else {
options.target([getESVersionTarget()])
}
})
},
}
Expand Down
11 changes: 11 additions & 0 deletions packages/rspeedy/core/src/utils/is-lynx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import type { EnvironmentContext } from '@rsbuild/core'

export function isLynx(environment: EnvironmentContext | string): boolean {
return typeof environment === 'string'
? environment === 'lynx'

Check warning on line 9 in packages/rspeedy/core/src/utils/is-lynx.ts

View check run for this annotation

Codecov / codecov/patch

packages/rspeedy/core/src/utils/is-lynx.ts#L9

Added line #L9 was not covered by tests
: environment.name === 'lynx'
}

Check warning on line 11 in packages/rspeedy/core/src/utils/is-lynx.ts

View check run for this annotation

Codecov / codecov/patch

packages/rspeedy/core/src/utils/is-lynx.ts#L11

Added line #L11 was not covered by tests
11 changes: 11 additions & 0 deletions packages/rspeedy/core/src/utils/is-web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import type { EnvironmentContext } from '@rsbuild/core'

export function isWeb(environment: EnvironmentContext | string): boolean {
return typeof environment === 'string'
? environment === 'web'

Check warning on line 9 in packages/rspeedy/core/src/utils/is-web.ts

View check run for this annotation

Codecov / codecov/patch

packages/rspeedy/core/src/utils/is-web.ts#L9

Added line #L9 was not covered by tests
: environment.name === 'web'
}

Check warning on line 11 in packages/rspeedy/core/src/utils/is-web.ts

View check run for this annotation

Codecov / codecov/patch

packages/rspeedy/core/src/utils/is-web.ts#L11

Added line #L11 was not covered by tests
67 changes: 67 additions & 0 deletions packages/rspeedy/core/test/plugins/chunkLoading.plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,71 @@ describe('Plugins - chunkLoading', () => {
),
).toBeTruthy()
})

describe('Web', () => {
test('Rspack', async () => {
const rspeedy = await createStubRspeedy({
environments: {
web: {},
},
})

const config = await rspeedy.unwrapConfig()

expect(config.output?.chunkLoading).toBe('import-scripts')
expect(config.output?.chunkFormat).not.toBe('commonjs')
expect(config.output?.iife).not.toBe(false)
})

test('Webpack', async () => {
const { webpackProvider } = await import('@rsbuild/webpack')
const rspeedy = await createStubRspeedy({
provider: webpackProvider,
environments: {
web: {},
},
})

const config = await rspeedy.unwrapConfig()

expect(config.output?.chunkLoading).toBe('import-scripts')
expect(config.output?.chunkFormat).not.toBe('commonjs')
expect(config.output?.iife).not.toBe(false)
})

test('multiple environments', async () => {
const rspeedy = await createStubRspeedy({
environments: {
web: {},
lynx: {},
},
})

const [webConfig, lynxConfig] = await rspeedy.initConfigs()

expect(webConfig?.output?.chunkLoading).toBe('import-scripts')
expect(webConfig?.output?.chunkFormat).not.toBe('commonjs')
expect(webConfig?.output?.iife).not.toBe(false)

expect(lynxConfig?.output?.chunkLoading).toBe('require')
expect(lynxConfig?.output?.chunkFormat).toBe('commonjs')
expect(lynxConfig?.output?.iife).toBe(false)
})

test('override with tools.rspack.output.chunkLoading', async () => {
const rspeedy = await createStubRspeedy({
environments: {
web: {
tools: {
rspack: { output: { chunkLoading: 'import' } },
},
},
},
})

const config = await rspeedy.unwrapConfig()

expect(config.output?.chunkLoading).toBe('import')
})
})
})
26 changes: 26 additions & 0 deletions packages/rspeedy/core/test/plugins/target.plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,30 @@ describe('target.plugin', () => {

expect(config.target).toEqual(['es2019'])
})

test('Web', async () => {
const rspeedy = await createStubRspeedy({
environments: {
web: {},
},
})

const config = await rspeedy.unwrapConfig()

expect(config.target).toEqual(['es2019', 'web'])
})

test('multiple environments', async () => {
const rspeedy = await createStubRspeedy({
environments: {
web: {},
lynx: {},
},
})

const [webConfig, lynxConfig] = await rspeedy.initConfigs()

expect(webConfig?.target).toEqual(['es2019', 'web'])
expect(lynxConfig?.target).toEqual(['es2019'])
})
})
10 changes: 0 additions & 10 deletions packages/web-platform/web-tests/tests/main-thread-apis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@ import {
} from '@lynx-js/web-constants';
import { test, expect } from './coverage-fixture.js';
import type { Page } from '@playwright/test';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import fs from 'node:fs/promises';
import v8toIstanbul from 'v8-to-istanbul';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const wait = async (ms: number) => {
await new Promise((resolve) => {
setTimeout(resolve, ms);
});
};

const getTitle = (titlePath: string[]) => {
return path.join(...[titlePath.pop()!, titlePath.pop()!].reverse());
};

test.describe('main thread api tests', () => {
test.beforeEach(async ({ page }) => {
await page.goto(`/main-thread-test.html`, {
Expand Down
22 changes: 3 additions & 19 deletions packages/web-platform/web-tests/tests/react.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
import { swipe, dragAndHold } from './utils.js';
import { test, expect } from './coverage-fixture.js';
import type { Page } from '@playwright/test';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import fs from 'node:fs/promises';
import v8toIstanbul from 'v8-to-istanbul';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const wait = async (ms: number) => {
await new Promise((resolve) => {
Expand Down Expand Up @@ -40,7 +34,7 @@

const expectHasText = async (page: Page, text: string) => {
const hasText = (await page.getByText(text).count()) === 1;
await expect(hasText).toBe(true);

Check failure on line 37 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:103:5 › reactlynx3 tests › basic › basic-setstate-in-constructor

2) [webkit] › tests/react.spec.ts:103:5 › reactlynx3 tests › basic › basic-setstate-in-constructor Error: expect(received).toBe(expected) // Object.is equality Expected: true Received: false 35 | const expectHasText = async (page: Page, text: string) => { 36 | const hasText = (await page.getByText(text).count()) === 1; > 37 | await expect(hasText).toBe(true); | ^ 38 | }; 39 | 40 | const expectNoText = async (page: Page, text: string) => { at expectHasText (/home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:37:25) at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:106:7

Check failure on line 37 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:108:5 › reactlynx3 tests › basic › basic-setsate-with-cb

3) [webkit] › tests/react.spec.ts:108:5 › reactlynx3 tests › basic › basic-setsate-with-cb ─────── Error: expect(received).toBe(expected) // Object.is equality Expected: true Received: false 35 | const expectHasText = async (page: Page, text: string) => { 36 | const hasText = (await page.getByText(text).count()) === 1; > 37 | await expect(hasText).toBe(true); | ^ 38 | }; 39 | 40 | const expectNoText = async (page: Page, text: string) => { at expectHasText (/home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:37:25) at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:111:7
};

const expectNoText = async (page: Page, text: string) => {
Expand Down Expand Up @@ -324,7 +318,7 @@
test('api-getJSModule', async ({ page }, { title }) => {
await goto(page, title);
await wait(1000);
expect(await page.locator('#target').getAttribute('style')).toContain(

Check failure on line 321 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:318:5 › reactlynx3 tests › apis › api-getJSModule

4) [webkit] › tests/react.spec.ts:318:5 › reactlynx3 tests › apis › api-getJSModule ────────────── Error: expect(received).toContain(expected) // indexOf Expected substring: "pink" Received string: "height: 100px; width: 100px; background: orange;" 319 | await goto(page, title); 320 | await wait(1000); > 321 | expect(await page.locator('#target').getAttribute('style')).toContain( | ^ 322 | 'pink', 323 | ); 324 | }); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:321:67
'pink',
);
});
Expand Down Expand Up @@ -498,7 +492,7 @@
await goto(page, title);
await wait(200);
const target = await page.locator('lynx-view');
expect(target).toHaveCSS('display', 'none');

Check failure on line 495 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:491:5 › reactlynx3 tests › apis › api-error

5) [webkit] › tests/react.spec.ts:491:5 › reactlynx3 tests › apis › api-error ──────────────────── Error: expect(locator).toHaveCSS(expected) Locator: locator('lynx-view') Expected string: "none" Received string: "" Call log: - expect.toHaveCSS with timeout 5000ms - waiting for locator('lynx-view') 493 | await wait(200); 494 | const target = await page.locator('lynx-view'); > 495 | expect(target).toHaveCSS('display', 'none'); | ^ 496 | }); 497 | 498 | test('api-preheat', async ({ page }, { title }) => { at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:495:22
});

test('api-preheat', async ({ page }, { title }) => {
Expand Down Expand Up @@ -964,7 +958,7 @@
await expect(target).toHaveCSS('height', '100px');
},
);
test.fixme( // TODO(@colinaaa): update the template plugin
test(
'config-splitchunk-single-vendor',
async ({ page }, { title }) => {
await goto(page, title, true);
Expand All @@ -973,7 +967,7 @@
await expect(target).toHaveCSS('background-color', 'rgb(0, 128, 0)'); // green
},
);
test.fixme( // TODO(@colinaaa): update the template plugin
test(
'config-splitchunk-split-by-experience',
async ({ page }, { title }) => {
await goto(page, title, true);
Expand All @@ -982,7 +976,7 @@
await expect(target).toHaveCSS('background-color', 'rgb(0, 128, 0)'); // green
},
);
test.fixme( // TODO(@colinaaa): update the template plugin
test(
'config-splitchunk-split-by-module',
async ({ page }, { title }) => {
await goto(page, title, true);
Expand All @@ -992,16 +986,6 @@
},
);

test.fixme( // TODO(@colinaaa): update the template plugin
'config-splitchunk-error-assertPrefix',
async ({ page }, { title }) => {
await goto(page, title, true);
await wait(1500);
const target = page.locator('#target');
await expect(target).toHaveCSS('background-color', 'rgb(0, 128, 0)'); // green
},
);

test('config-mode-dev-with-all-in-one', async ({ page }, { title }) => {
await goto(page, title, true);
await wait(100);
Expand Down Expand Up @@ -1274,7 +1258,7 @@
await wait(200);
// --initialtextinitial
let count = await page.getByText('--').count();
expect(count).toBe(1);

Check failure on line 1261 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:1254:7 › reactlynx3 tests › elements › text › basic-element-text-set-native-props-with-setData

6) [webkit] › tests/react.spec.ts:1254:7 › reactlynx3 tests › elements › text › basic-element-text-set-native-props-with-setData Error: expect(received).toBe(expected) // Object.is equality Expected: 1 Received: 0 1259 | // --initialtextinitial 1260 | let count = await page.getByText('--').count(); > 1261 | expect(count).toBe(1); | ^ 1262 | count = await page.getByText('initial').count(); 1263 | expect(count).toBeGreaterThanOrEqual(1); 1264 | await page.locator('#target').click(); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1261:25
count = await page.getByText('initial').count();
expect(count).toBeGreaterThanOrEqual(1);
await page.locator('#target').click();
Expand Down Expand Up @@ -1536,7 +1520,7 @@
}) => {
await goto(page, title);
await wait(300);
await page.evaluate(() => {

Check failure on line 1523 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:1516:7 › reactlynx3 tests › elements › scroll-view › basic-element-scroll-view-event-scrollend

7) [webkit] › tests/react.spec.ts:1516:7 › reactlynx3 tests › elements › scroll-view › basic-element-scroll-view-event-scrollend Error: page.evaluate: TypeError: null is not an object (evaluating 'document.querySelector('lynx-view').shadowRoot.querySelector('scroll-view').scrollTop = 200') 1521 | await goto(page, title); 1522 | await wait(300); > 1523 | await page.evaluate(() => { | ^ 1524 | document.querySelector('lynx-view')!.shadowRoot!.querySelector( 1525 | 'scroll-view', 1526 | )!.scrollTop = 200; at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1523:22
document.querySelector('lynx-view')!.shadowRoot!.querySelector(
'scroll-view',
)!.scrollTop = 200;
Expand Down Expand Up @@ -1942,7 +1926,7 @@
await wait(100);
await page.locator('input').fill('foobar');
const result = await page.locator('.result').first().innerText();
expect(result).toBe('foobar');

Check failure on line 1929 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[webkit] › tests/react.spec.ts:1923:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindinput

8) [webkit] › tests/react.spec.ts:1923:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindinput Error: expect(received).toBe(expected) // Object.is equality Expected: "foobar" Received: "" 1927 | await page.locator('input').fill('foobar'); 1928 | const result = await page.locator('.result').first().innerText(); > 1929 | expect(result).toBe('foobar'); | ^ 1930 | }); 1931 | // input/bindinput test-case end 1932 | }); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1929:24

Check failure on line 1929 in packages/web-platform/web-tests/tests/react.spec.ts

View workflow job for this annotation

GitHub Actions / playwright-linux / check

[chromium] › tests/react.spec.ts:1923:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindinput

9) [chromium] › tests/react.spec.ts:1923:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindinput Error: expect(received).toBe(expected) // Object.is equality Expected: "foobar" Received: "" 1927 | await page.locator('input').fill('foobar'); 1928 | const result = await page.locator('.result').first().innerText(); > 1929 | expect(result).toBe('foobar'); | ^ 1930 | }); 1931 | // input/bindinput test-case end 1932 | }); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1929:24
});
// input/bindinput test-case end
});
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export default defineConfig({
},
performance: {
chunkSplit: {
// Rspack 1.2.8 introduced a bug that causes the single-vendor strategy to fail.
// strategy: 'single-vendor',
strategy: 'single-vendor',
override: {
// See: https://github.com/web-infra-dev/rspack/issues/9812
filename: '[name].[contenthash:8].js',
},
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export default defineConfig({
},
performance: {
chunkSplit: {
// Rspack 1.2.8 introduced a bug that causes the split-by-experience strategy to fail.
// strategy: 'split-by-experience',
strategy: 'split-by-experience',
override: {
// See: https://github.com/web-infra-dev/rspack/issues/9812
filename: '[name].[contenthash:8].js',
},
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export default defineConfig({
},
performance: {
chunkSplit: {
// Rspack 1.2.8 introduced a bug that causes the split-by-module strategy to fail.
// strategy: 'split-by-module',
strategy: 'split-by-module',
override: {
// See: https://github.com/web-infra-dev/rspack/issues/9812
filename: '[name].[contenthash:8].js',
},
},
},
});
Loading
Loading