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
10 changes: 10 additions & 0 deletions .changeset/twenty-suits-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@lynx-js/web-core": minor
---

feat: upgrade @lynx-js/lynx-core to 0.1.2

refactor some internal logic

- __OnLifeCycleEvent
- __OnNativeAppReady
28 changes: 7 additions & 21 deletions packages/web-platform/web-constants/src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
} from './types/EventType.js';
import type { Cloneable, CloneableObject } from './types/Cloneable.js';
import type { MainThreadStartConfigs } from './types/MainThreadStartConfigs.js';
import type { LynxLifecycleEvent } from './types/LynxLifecycleEvent.js';
import type { IdentifierType, InvokeCallbackRes } from './types/NativeApp.js';
import type { LynxTemplate } from './types/LynxModule.js';
import type { NapiModulesMap } from './types/NapiModules.js';
Expand Down Expand Up @@ -74,21 +73,6 @@ export const disposeEndpoint = createRpcEndpoint<
void
>('dispose', false, true);

export const uiThreadFpReadyEndpoint = createRpcEndpoint<[], void>(
'uiThreadFpReady',
false,
false,
);

export const onLifecycleEventEndpoint = createRpcEndpoint<
[LynxLifecycleEvent],
void
>(
'__OnLifecycleEvent',
false,
false,
);

export const BackgroundThreadStartEndpoint = createRpcEndpoint<[
{
initData: unknown;
Expand Down Expand Up @@ -116,11 +100,6 @@ export const flushElementTreeEndpoint = createRpcEndpoint<
void
>('flushElementTree', false, true);

export const mainThreadChunkReadyEndpoint = createRpcEndpoint<
[],
void
>('mainThreadChunkReady', false, false);

export const callLepusMethodEndpoint = createRpcEndpoint<
[name: string, data: unknown],
void
Expand Down Expand Up @@ -215,3 +194,10 @@ export const dispatchNapiModuleEndpoint = createRpcEndpoint<
[data: Cloneable],
void
>('dispatchNapiModule', false, false);
export const dispatchCoreContextEventEndpoint = createRpcEndpoint<
[
eventType: string,
data: Cloneable | undefined | null,
],
void
>('dispatchCoreContextEventEndpoint', false, false);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// LICENSE file in the root directory of this source tree.
export type Cloneable<T = string | number | null | undefined> =
| T
| Record<string, T>;
| Record<string, T>
| T[];

export type CloneableObject<T = string | number | null | undefined> = Record<
string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const DispatchEventResult = {
// Event was not canceled by event handler or default event handler.
NotCanceled: 0,
// Event was canceled by event handler; i.e. a script handler calling
// preventDefault.
CanceledByEventHandler: 1,
// Event was canceled by the default event handler; i.e. executing the default
// action. This result should be used sparingly as it deviates from the DOM
// Event Dispatch model. Default event handlers really shouldn't be invoked
// inside of dispatch.
CanceledByDefaultEventHandler: 2,
// Event was canceled but suppressed before dispatched to event handler. This
// result should be used sparingly; and its usage likely indicates there is
// potential for a bug. Trusted events may return this code; but untrusted
// events likely should always execute the event handler the developer intends
// to execute.
CanceledBeforeDispatch: 3,
} as const;
export interface LynxContextEventTarget {
onTriggerEvent?: (event: MessageEvent) => void;

postMessage(message: any): void;
dispatchEvent(
event: MessageEvent,
): typeof DispatchEventResult[keyof typeof DispatchEventResult];
addEventListener(type: string, listener: (event: MessageEvent) => void): void;
removeEventListener(
type: string,
listener: (event: MessageEvent) => void,
): void;
}

This file was deleted.

51 changes: 21 additions & 30 deletions packages/web-platform/web-constants/src/types/NativeApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License Version 2.0 that can be found in the

import type { CloneableObject } from './Cloneable.js';
import type { LynxContextEventTarget } from './LynxContextEventTarget.js';
import type { PerformancePipelineOptions } from './Performance.js';

// LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -39,8 +40,17 @@ export interface EventEmitter {
toggle(eventName: string, ...data: unknown[]): void;
}

export type NativeLynx = {
__globalProps: CloneableObject;
getJSModule(_moduleName: string): unknown;
getNativeApp(): NativeApp;
getCoreContext(): LynxContextEventTarget;
getCustomSectionSync(key: string): CloneableObject;
getCustomSection(key: string): Promise<CloneableObject>;
};

export type NativeTTObject = {
lynx: unknown;
lynx: NativeLynx;
OnLifecycleEvent: (...args: unknown[]) => void;
publicComponentEvent(
componentId: string,
Expand Down Expand Up @@ -90,35 +100,6 @@ export interface InvokeCallbackRes {
data?: string;
}

export enum DispatchEventResult {
// Event was not canceled by event handler or default event handler.
NotCanceled = 0,
// Event was canceled by event handler; i.e. a script handler calling
// preventDefault.
CanceledByEventHandler,
// Event was canceled by the default event handler; i.e. executing the default
// action. This result should be used sparingly as it deviates from the DOM
// Event Dispatch model. Default event handlers really shouldn't be invoked
// inside of dispatch.
CanceledByDefaultEventHandler,
// Event was canceled but suppressed before dispatched to event handler. This
// result should be used sparingly; and its usage likely indicates there is
// potential for a bug. Trusted events may return this code; but untrusted
// events likely should always execute the event handler the developer intends
// to execute.
CanceledBeforeDispatch,
}
export interface ContextProxy {
onTriggerEvent?: (event: MessageEvent) => void;

postMessage(message: any): void;
dispatchEvent(event: MessageEvent): DispatchEventResult;
addEventListener(type: string, listener: (event: MessageEvent) => void): void;
removeEventListener(
type: string,
listener: (event: MessageEvent) => void,
): void;
}
export interface NativeApp {
id: string;

Expand Down Expand Up @@ -178,6 +159,16 @@ export interface NativeApp {
timing_flag: string,
) => void;

/**
* Support from Lynx 3.0
*/
profileStart: (traceName: string, option?: unknown) => void;

/**
* Support from Lynx 3.0
*/
profileEnd: () => void;

triggerComponentEvent(id: string, params: {
eventDetail: CloneableObject;
eventOption: CloneableObject;
Expand Down
2 changes: 1 addition & 1 deletion packages/web-platform/web-constants/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from './EventType.js';
export * from './PageConfig.js';
export * from './Cloneable.js';
export * from './LynxModule.js';
export * from './LynxLifecycleEvent.js';
export * from './ProcessDataCallback.js';
export * from './Performance.js';
export * from './MainThreadStartConfigs.js';
Expand All @@ -12,3 +11,4 @@ export * from './UpdateDataOptions.js';
export * from './NativeModules.js';
export * from './NapiModules.js';
export * from './FlushElementTreeOptions.js';
export * from './LynxContextEventTarget.js';
4 changes: 2 additions & 2 deletions packages/web-platform/web-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"@lynx-js/web-worker-runtime": "workspace:*"
},
"devDependencies": {
"@lynx-js/lynx-core": "0.1.0",
"@lynx-js/lynx-core": "0.1.2",
"@lynx-js/web-elements": "workspace:*"
},
"peerDependencies": {
"@lynx-js/lynx-core": "0.1.0",
"@lynx-js/lynx-core": "0.1.2",
"@lynx-js/web-elements": ">=0.3.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export function registerFlushElementTreeHandler(
options: {
shadowRoot: ShadowRoot;
},
onCommit: (info: {
isFP: boolean;
}) => void,
) {
const {
shadowRoot,
Expand All @@ -25,17 +22,10 @@ export function registerFlushElementTreeHandler(
shadowRoot,
onEvent,
});
let isFP = true;
mainThreadRpc.registerHandler(
flushElementTreeEndpoint,
(operations) => {
decodeOperation(operations);
onCommit({
isFP,
});
if (isFP) {
isFP = false;
}
},
);
}
54 changes: 20 additions & 34 deletions packages/web-platform/web-core/src/uiThread/startUIThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import { createDispose } from './crossThreadHandlers/createDispose.js';
import { registerTriggerComponentEventHandler } from './crossThreadHandlers/registerTriggerComponentEventHandler.js';
import { registerSelectComponentHandler } from './crossThreadHandlers/registerSelectComponentHandler.js';
import {
mainThreadChunkReadyEndpoint,
mainThreadStartEndpoint,
markTimingEndpoint,
sendGlobalEventEndpoint,
uiThreadFpReadyEndpoint,
type MainThreadStartConfigs,
type NapiModulesCall,
type NativeModulesCall,
Expand Down Expand Up @@ -45,7 +43,6 @@ export function startUIThread(
terminateWorkers,
} = bootWorkers();
const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
const uiThreadFpReady = backgroundRpc.createCall(uiThreadFpReadyEndpoint);
const mainThreadStart = mainThreadRpc.createCall(mainThreadStartEndpoint);
const markTiming = backgroundRpc.createCall(markTimingEndpoint);
const markTimingInternal = (
Expand All @@ -72,39 +69,28 @@ export function startUIThread(
callbacks.onError,
);
registerDispatchLynxViewEventHandler(backgroundRpc, shadowRoot);
mainThreadRpc.registerHandler(
mainThreadChunkReadyEndpoint,
() => {
registerFlushElementTreeHandler(
mainThreadRpc,
{
shadowRoot,
},
(info) => {
const { isFP } = info;
if (isFP) {
registerInvokeUIMethodHandler(
backgroundRpc,
shadowRoot,
);
registerNativePropsHandler(
backgroundRpc,
shadowRoot,
);
registerTriggerComponentEventHandler(
backgroundRpc,
shadowRoot,
);
registerSelectComponentHandler(
backgroundRpc,
shadowRoot,
);
uiThreadFpReady();
}
},
);
registerFlushElementTreeHandler(
mainThreadRpc,
{
shadowRoot,
},
);
registerInvokeUIMethodHandler(
backgroundRpc,
shadowRoot,
);
registerNativePropsHandler(
backgroundRpc,
shadowRoot,
);
registerTriggerComponentEventHandler(
backgroundRpc,
shadowRoot,
);
registerSelectComponentHandler(
backgroundRpc,
shadowRoot,
);
registerNativeModulesCallHandler(
backgroundRpc,
callbacks.nativeModulesCall,
Expand Down
2 changes: 1 addition & 1 deletion packages/web-platform/web-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"devDependencies": {
"@codecov/webpack-plugin": "^1.9.0",
"@lynx-js/lynx-core": "0.1.0",
"@lynx-js/lynx-core": "0.1.2",
"@lynx-js/web-core": "workspace:*",
"@lynx-js/web-elements": "workspace:*",
"@rsbuild/core": "catalog:rsbuild",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
type publishEventEndpoint,
type publicComponentEventEndpoint,
type reportErrorEndpoint,
type onLifecycleEventEndpoint,
type RpcCallType,
type postExposureEndpoint,
} from '@lynx-js/web-constants';
Expand All @@ -42,7 +41,7 @@ export interface MainThreadRuntimeCallbacks {
timingFlags: string[],
) => void;
_ReportError: RpcCallType<typeof reportErrorEndpoint>;
__OnLifecycleEvent: RpcCallType<typeof onLifecycleEventEndpoint>;
__OnLifecycleEvent: (lifeCycleEvent: Cloneable) => void;
markTiming: (pipelineId: string, timingKey: string) => void;
publishEvent: RpcCallType<typeof publishEventEndpoint>;
publicComponentEvent: RpcCallType<typeof publicComponentEventEndpoint>;
Expand Down Expand Up @@ -215,7 +214,7 @@ export class MainThreadRuntime {

_ReportError: RpcCallType<typeof reportErrorEndpoint>;

__OnLifecycleEvent: RpcCallType<typeof onLifecycleEventEndpoint>;
__OnLifecycleEvent: (lifeCycleEvent: Cloneable) => void;

__LoadLepusChunk: (path: string) => boolean = (path) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-platform/web-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test:update": "playwright test --ui --update-snapshots"
},
"devDependencies": {
"@lynx-js/lynx-core": "0.1.0",
"@lynx-js/lynx-core": "0.1.2",
"@lynx-js/offscreen-document": "workspace:*",
"@lynx-js/react": "workspace:*",
"@lynx-js/react-rsbuild-plugin": "workspace:*",
Expand Down
12 changes: 0 additions & 12 deletions packages/web-platform/web-tests/tests/react.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,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:104:5 › reactlynx3 tests › basic › basic-setstate-in-constructor

3) [webkit] › tests/react.spec.ts:104: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:107: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:109:5 › reactlynx3 tests › basic › basic-setsate-with-cb

4) [webkit] › tests/react.spec.ts:109: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:112:7
};

const expectNoText = async (page: Page, text: string) => {
Expand Down Expand Up @@ -79,7 +79,7 @@
await wait(100);
const target = page.locator('#target');
await target.click();
await expect(await target.getAttribute('style')).toContain('green');

Check failure on line 82 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:77:5 › reactlynx3 tests › basic › basic-bindtap

2) [webkit] › tests/react.spec.ts:77:5 › reactlynx3 tests › basic › basic-bindtap ──────────────── Error: expect(received).toContain(expected) // indexOf Expected substring: "green" Received string: "height: 100px; width: 100px; background: pink;" 80 | const target = page.locator('#target'); 81 | await target.click(); > 82 | await expect(await target.getAttribute('style')).toContain('green'); | ^ 83 | await target.click(); 84 | await expect(await target.getAttribute('style')).toContain('pink'); 85 | }); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:82:56
await target.click();
await expect(await target.getAttribute('style')).toContain('pink');
});
Expand Down Expand Up @@ -455,18 +455,6 @@
await expect(successCallback).toBe(true);
});

test('api-onNativeAppReady', async ({ page }, { title }) => {
const messages: string[] = [];
await page.on('console', async (message) => {
for (const arg of message.args()) {
messages.push(JSON.stringify(await arg.jsonValue()));
}
});
await goto(page, title);
await wait(500);
expect(messages.join(',')).toContain('uiThreadFpReady');
});

test('basic-at-rule-animation', async ({ page }, { title }) => {
await goto(page, title);
const target = page.locator('#target');
Expand Down Expand Up @@ -805,7 +793,7 @@
globalThis.lynxView.sendGlobalEvent('event-test', ['change']);
});
await wait(100);
await expect(target).toHaveCSS(

Check failure on line 796 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:787:5 › reactlynx3 tests › apis › api-sendGlobalEvent

8) [chromium] › tests/react.spec.ts:787:5 › reactlynx3 tests › apis › api-sendGlobalEvent ──────── Error: Timed out 5000ms waiting for expect(locator).toHaveCSS(expected) Locator: locator('#target') Expected string: "rgb(0, 128, 0)" Received string: "rgb(255, 192, 203)" Call log: - expect.toHaveCSS with timeout 5000ms - waiting for locator('#target') 9 × locator resolved to <x-view id="target" lynx-tag="view" lynx-unique-id="2"></x-view> - unexpected value "rgb(255, 192, 203)" 794 | }); 795 | await wait(100); > 796 | await expect(target).toHaveCSS( | ^ 797 | 'background-color', 798 | 'rgb(0, 128, 0)', 799 | ); // green; at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:796:28
'background-color',
'rgb(0, 128, 0)',
); // green;
Expand Down Expand Up @@ -1006,7 +994,7 @@
await wait(100);
const target = page.locator('#target');
await target.click();
await expect(await target.getAttribute('style')).toContain('green');

Check failure on line 997 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:992:5 › reactlynx3 tests › configs › config-mode-dev-with-all-in-one

5) [webkit] › tests/react.spec.ts:992:5 › reactlynx3 tests › configs › config-mode-dev-with-all-in-one Error: expect(received).toContain(expected) // indexOf Expected substring: "green" Received string: "height: 100px; width: 100px; background: pink;" 995 | const target = page.locator('#target'); 996 | await target.click(); > 997 | await expect(await target.getAttribute('style')).toContain('green'); | ^ 998 | await target.click(); 999 | await expect(await target.getAttribute('style')).toContain('pink'); 1000 | }); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:997:56
await target.click();
await expect(await target.getAttribute('style')).toContain('pink');
});
Expand Down Expand Up @@ -1246,7 +1234,7 @@
await wait(500);
const count = (await page.getByText('the count is:1').count())
+ (await await page.getByText('the count is:2').count());
expect(count).toBe(1);

Check failure on line 1237 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:1230:7 › reactlynx3 tests › elements › text › basic-element-text-set-native-props-text

6) [webkit] › tests/react.spec.ts:1230:7 › reactlynx3 tests › elements › text › basic-element-text-set-native-props-text Error: expect(received).toBe(expected) // Object.is equality Expected: 1 Received: 0 1235 | const count = (await page.getByText('the count is:1').count()) 1236 | + (await await page.getByText('the count is:2').count()); > 1237 | expect(count).toBe(1); | ^ 1238 | }, 1239 | ); 1240 | at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1237:25
},
);

Expand Down Expand Up @@ -1285,7 +1273,7 @@
await wait(300);
// --initialtextinitial
let count = await page.getByText('--').count();
expect(count).toBe(1);

Check failure on line 1276 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:1269:7 › reactlynx3 tests › elements › text › basic-element-text-set-native-props-with-setData

7) [webkit] › tests/react.spec.ts:1269: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 1274 | // --initialtextinitial 1275 | let count = await page.getByText('--').count(); > 1276 | expect(count).toBe(1); | ^ 1277 | count = await page.getByText('initial').count(); 1278 | expect(count).toBeGreaterThanOrEqual(1); 1279 | await page.locator('#target').click(); at /home/runner/_work/lynx-stack/lynx-stack/packages/web-platform/web-tests/tests/react.spec.ts:1276:25
count = await page.getByText('initial').count();
expect(count).toBeGreaterThanOrEqual(1);
await page.locator('#target').click();
Expand Down
Loading
Loading