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/nasty-pens-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-mainthread-apis": patch
---

fix: fix reload lynx-view when `enableCSSSelector` false may cause css style lost
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export async function createLynxView(
]);
},
},
threadStrategy === 'all-on-ui',
);
await startMainThread({
template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export function createRenderAllOnUI(
return i18nResources;
},
loadTemplate,
undefined,
true,
);

const start = async (configs: StartMainThreadContextConfig) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function prepareMainThreadAPIs(
initialI18nResources: (data: InitI18nResources) => I18nResources,
loadTemplate: TemplateLoader,
ssrHooks?: SSRDehydrateHooks,
allOnUI?: boolean,
) {
const postTimingFlags = backgroundThreadRpc.createCall(
postTimingFlagsEndpoint,
Expand Down Expand Up @@ -110,6 +111,7 @@ export function prepareMainThreadAPIs(
rootDom as unknown as Node,
document,
ssrHydrateInfo,
allOnUI,
);
const mtsGlobalThisRef: { mtsGlobalThis: MainThreadGlobalThis } = {
mtsGlobalThis: undefined as unknown as MainThreadGlobalThis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function generateImportByMap(
*/
export function flattenStyleInfo(
styleInfo: StyleInfo,
cloneDeep?: boolean,
): FlattenedStyleInfo {
// Step 1. Topological sorting
const sortedCssIds = topologicalSort(styleInfo);
Expand All @@ -98,8 +99,19 @@ export function flattenStyleInfo(
const oneInfo = styleInfo[cssId];
const flattenedInfo: FlattenedOneInfo = oneInfo
? {
content: oneInfo.content,
rules: oneInfo.rules,
content: cloneDeep
? (oneInfo.content ? [...oneInfo.content] : [])
: (oneInfo.content ?? []),
rules: cloneDeep
? (oneInfo.rules
? oneInfo.rules.map(rule => ({
sel: rule.sel.map(selectors =>
selectors.map(arr => arr.slice()) as typeof selectors
) as CSSRule['sel'],
decl: rule.decl.map(([k, v]) => [k, v]) as typeof rule.decl,
}))
: [])
: (oneInfo.rules ?? []),
importBy: Array.from(cssIdToImportBy.get(cssId) ?? [cssId]),
}
: {
Expand Down Expand Up @@ -242,6 +254,7 @@ export function appendStyleElement(
rootDom: Node,
document: Document,
ssrHydrateInfo?: SSRHydrateInfo,
allOnUI?: boolean,
) {
const lynxUniqueIdToStyleRulesIndex: number[] =
ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
Expand All @@ -255,6 +268,7 @@ export function appendStyleElement(
*/
const flattenedStyleInfo = flattenStyleInfo(
styleInfo,
!!allOnUI,
);
transformToWebCss(flattenedStyleInfo);
const cssOGInfo: CssOGInfo = pageConfig.enableCSSSelector
Expand Down Expand Up @@ -303,7 +317,7 @@ export function appendStyleElement(
styleInfo: StyleInfo,
entryName: string,
) => {
const flattenedStyleInfo = flattenStyleInfo(styleInfo);
const flattenedStyleInfo = flattenStyleInfo(styleInfo, !!allOnUI);
transformToWebCss(flattenedStyleInfo);
if (!pageConfig.enableCSSSelector) {
lazyCSSOGInfo[entryName] = genCssOGInfo(flattenedStyleInfo);
Expand Down
17 changes: 17 additions & 0 deletions packages/web-platform/web-tests/tests/react.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// 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.
Expand All @@ -23,7 +23,7 @@
ReturnType<typeof expect<Page>>['toHaveScreenshot']
>[0],
) => {
await expect(page).toHaveScreenshot([

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

View workflow job for this annotation

GitHub Actions / Playwright MULTI_THREAD-CSR (1/4) / check

[webkit] › tests/react.spec.ts:2395:7 › reactlynx3 tests › elements › image › basic-element-image-src

4) [webkit] › tests/react.spec.ts:2395:7 › reactlynx3 tests › elements › image › basic-element-image-src Error: expect(page).toHaveScreenshot(expected) failed 8220 pixels (ratio 0.04 of all image pixels) are different. Snapshot: image/basic-element-image-src/index.png Call log: - Expect "toHaveScreenshot(image/basic-element-image-src/index.png)" with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - waiting for fonts to load... - fonts loaded - 8220 pixels (ratio 0.04 of all image pixels) are different. - waiting 100ms before taking screenshot - taking page screenshot - waiting for fonts to load... - fonts loaded - captured a stable screenshot - 8220 pixels (ratio 0.04 of all image pixels) are different. 24 | >[0], 25 | ) => { > 26 | await expect(page).toHaveScreenshot([ | ^ 27 | `${caseName}`, 28 | `${subcaseName}`, 29 | `${label}.png`, at diffScreenShot (/__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:26:22) at /__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2397:15
`${caseName}`,
`${subcaseName}`,
`${label}.png`,
Expand Down Expand Up @@ -58,7 +58,7 @@
if (testname2) {
url += `&casename2=${testname2}`;
}
await page.goto(url, {

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

View workflow job for this annotation

GitHub Actions / Playwright MULTI_THREAD-CSR (1/4) / check

[webkit] › tests/react.spec.ts:817:5 › reactlynx3 tests › basic › basic-lazy-component-css-selector-false-remove-inline-style-and-reuse-css

2) [webkit] › tests/react.spec.ts:817:5 › reactlynx3 tests › basic › basic-lazy-component-css-selector-false-remove-inline-style-and-reuse-css Error: page.goto: Test timeout of 30000ms exceeded. Call log: - navigating to "http://localhost:3080/?casename=basic-lazy-component-css-selector-false-remove-inline-style-and-reuse-css", waiting until "load" 59 | url += `&casename2=${testname2}`; 60 | } > 61 | await page.goto(url, { | ^ 62 | waitUntil: 'load', 63 | }); 64 | await page.evaluate(() => document.fonts.ready); at goto (/__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:61:14) at /__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:820:15
waitUntil: 'load',
});
await page.evaluate(() => document.fonts.ready);
Expand Down Expand Up @@ -1839,6 +1839,23 @@
).toHaveCSS('background-color', 'rgb(0, 128, 0)');
},
);
test(
'config-css-selector-false-reload',
async ({ page }, { title }) => {
await goto(page, title);
await wait(100);
await expect(
page.locator('#target'),
).toHaveCSS('background-color', 'rgb(255, 0, 0)');
await page.evaluate(() => {
document.querySelector('lynx-view')?.reload();
});
await wait(1000);
await expect(
page.locator('#target'),
).toHaveCSS('background-color', 'rgb(255, 0, 0)');
},
);
test(
'config-css-remove-scope-false-import-css',
async ({ page }, { title }) => {
Expand Down Expand Up @@ -2059,7 +2076,7 @@
const elementName = 'lynx-view';
test('basic-element-lynx-view-not-auto', async ({ page }, { title }) => {
await goto(page, title);
await page.evaluate(() => {

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

View workflow job for this annotation

GitHub Actions / Playwright MULTI_THREAD-CSR (1/4) / check

[webkit] › tests/react.spec.ts:2077:7 › reactlynx3 tests › elements › lynx-view › basic-element-lynx-view-not-auto

3) [webkit] › tests/react.spec.ts:2077:7 › reactlynx3 tests › elements › lynx-view › basic-element-lynx-view-not-auto Error: page.evaluate: TypeError: null is not an object (evaluating 'document.querySelector('lynx-view').setAttribute') 2077 | test('basic-element-lynx-view-not-auto', async ({ page }, { title }) => { 2078 | await goto(page, title); > 2079 | await page.evaluate(() => { | ^ 2080 | document.querySelector('lynx-view')!.setAttribute('width', '100vw'); 2081 | document.querySelector('lynx-view')!.setAttribute('height', '100vh'); 2082 | document.querySelector('lynx-view')!.setAttribute( at /__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:2079:20
document.querySelector('lynx-view')!.setAttribute('width', '100vw');
document.querySelector('lynx-view')!.setAttribute('height', '100vh');
document.querySelector('lynx-view')!.setAttribute(
Expand Down Expand Up @@ -3118,7 +3135,7 @@
inputDom?.setSelectionRange(2, 5);
});
const result = await page.locator('.result').first().innerText();
expect(result).toBe('2-5');

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

View workflow job for this annotation

GitHub Actions / Playwright MULTI_THREAD-CSR (1/4) / check

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

5) [webkit] › tests/react.spec.ts:3126:7 › reactlynx3 tests › elements › x-input › basic-element-x-input-bindselection Error: expect(received).toBe(expected) // Object.is equality Expected: "2-5" Received: "" 3136 | }); 3137 | const result = await page.locator('.result').first().innerText(); > 3138 | expect(result).toBe('2-5'); | ^ 3139 | }, 3140 | ); 3141 | test( at /__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:3138:26
},
);
test(
Expand Down Expand Up @@ -4684,7 +4701,7 @@

await goto(page, title);
await wait(5000);
expect(scrolltolower).toBeTruthy();

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

View workflow job for this annotation

GitHub Actions / Playwright MULTI_THREAD-CSR (2/4) / check

[chromium] › tests/react.spec.ts:4688:7 › reactlynx3 tests › elements › list › basic-element-list-horizontal-estimated-main-axis-size-px-waterfall

2) [chromium] › tests/react.spec.ts:4688:7 › reactlynx3 tests › elements › list › basic-element-list-horizontal-estimated-main-axis-size-px-waterfall Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBeTruthy() Received: false 4702 | await goto(page, title); 4703 | await wait(5000); > 4704 | expect(scrolltolower).toBeTruthy(); | ^ 4705 | }, 4706 | ); 4707 | }); at /__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:4704:33

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

View workflow job for this annotation

GitHub Actions / Playwright MULTI_THREAD-CSR (2/4) / check

[chromium] › tests/react.spec.ts:4688:7 › reactlynx3 tests › elements › list › basic-element-list-horizontal-estimated-main-axis-size-px-waterfall

2) [chromium] › tests/react.spec.ts:4688:7 › reactlynx3 tests › elements › list › basic-element-list-horizontal-estimated-main-axis-size-px-waterfall Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBeTruthy() Received: false 4702 | await goto(page, title); 4703 | await wait(5000); > 4704 | expect(scrolltolower).toBeTruthy(); | ^ 4705 | }, 4706 | ); 4707 | }); at /__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:4704:33

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

View workflow job for this annotation

GitHub Actions / Playwright MULTI_THREAD-CSR (2/4) / check

[chromium] › tests/react.spec.ts:4688:7 › reactlynx3 tests › elements › list › basic-element-list-horizontal-estimated-main-axis-size-px-waterfall

2) [chromium] › tests/react.spec.ts:4688:7 › reactlynx3 tests › elements › list › basic-element-list-horizontal-estimated-main-axis-size-px-waterfall Error: expect(received).toBeTruthy() Received: false 4702 | await goto(page, title); 4703 | await wait(5000); > 4704 | expect(scrolltolower).toBeTruthy(); | ^ 4705 | }, 4706 | ); 4707 | }); at /__w/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:4704:33
},
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
// Copyright 2023 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.
*/

.parent {
width: 200px;
height: 200px;
background-color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 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 { root, Component } from '@lynx-js/react';
import './index.css';
export default class App extends Component {
render() {
return (
<view id='target' class='parent'>
</view>
);
}
}

root.render(<App></App>);
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export async function startMainThreadWorker(
return i18nResources;
},
loadTemplate,
undefined,
false,
);
uiThreadRpc.registerHandler(
mainThreadStartEndpoint,
Expand Down
Loading