@lynx-js/react 0.106.2 → 0.106.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/package.json +3 -3
- package/refresh/.turbo/turbo-build.log +1 -1
- package/refresh/package.json +1 -1
- package/runtime/lib/lifecycle/destroy.js +8 -0
- package/runtime/lib/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/lifecycle/event/delayEvents.d.ts +3 -0
- package/runtime/lib/lifecycle/event/delayEvents.js +7 -0
- package/runtime/lib/lifecycle/event/delayEvents.js.map +1 -0
- package/runtime/lib/lifecycle/event/delayLifecycleEvents.d.ts +3 -0
- package/runtime/lib/lifecycle/event/delayLifecycleEvents.js +20 -0
- package/runtime/lib/lifecycle/event/delayLifecycleEvents.js.map +1 -0
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js +10 -10
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/lynx/calledByNative.js +2 -0
- package/runtime/lib/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/lynx/tt.d.ts +1 -2
- package/runtime/lib/lynx/tt.js +20 -20
- package/runtime/lib/lynx/tt.js.map +1 -1
- package/runtime/lib/lynx-api.js +5 -2
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/snapshot.d.ts +1 -0
- package/runtime/lib/snapshot.js +4 -0
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/lib/worklet/hmr.js +19 -12
- package/runtime/lib/worklet/hmr.js.map +1 -1
- package/runtime/src/lifecycle/destroy.ts +8 -1
- package/runtime/src/lifecycle/event/delayEvents.ts +8 -0
- package/runtime/src/lifecycle/event/delayLifecycleEvents.ts +21 -0
- package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +10 -10
- package/runtime/src/lynx/calledByNative.ts +2 -0
- package/runtime/src/lynx/tt.ts +23 -20
- package/runtime/src/lynx-api.ts +5 -4
- package/runtime/src/snapshot.ts +5 -0
- package/runtime/src/worklet/hmr.ts +19 -15
- package/transform/dist/wasm.cjs +1 -1
|
@@ -40,6 +40,8 @@ function ssrHydrate(info: string) {
|
|
|
40
40
|
throw new Error('SSR Hydration Failed! Please check if the SSR content loaded successfully!');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
resetJSReady();
|
|
44
|
+
setupPage(nativePage);
|
|
43
45
|
const refsMap = __GetTemplateParts(nativePage);
|
|
44
46
|
|
|
45
47
|
const { __opcodes, __root_values } = JSON.parse(info);
|
package/runtime/src/lynx/tt.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { LifecycleConstant, NativeUpdateDataType } from '../lifecycleConstant.js
|
|
|
8
8
|
import { PerformanceTimingKeys, beginPipeline, markTiming } from './performance.js';
|
|
9
9
|
import { BackgroundSnapshotInstance, hydrate } from '../backgroundSnapshot.js';
|
|
10
10
|
import { destroyBackground } from '../lifecycle/destroy.js';
|
|
11
|
+
import { delayedEvents, delayedPublishEvent } from '../lifecycle/event/delayEvents.js';
|
|
12
|
+
import { delayLifecycleEvent, delayedLifecycleEvents } from '../lifecycle/event/delayLifecycleEvents.js';
|
|
11
13
|
import { commitPatchUpdate, genCommitTaskId, globalCommitTaskMap } from '../lifecycle/patch/commit.js';
|
|
12
14
|
import { reloadBackground } from '../lifecycle/reload.js';
|
|
13
15
|
import { renderBackground } from '../lifecycle/render.js';
|
|
@@ -69,7 +71,7 @@ export function runWithForce(cb: () => void): void {
|
|
|
69
71
|
function injectTt(): void {
|
|
70
72
|
// @ts-ignore
|
|
71
73
|
const tt = lynxCoreInject.tt;
|
|
72
|
-
tt.OnLifecycleEvent =
|
|
74
|
+
tt.OnLifecycleEvent = onLifecycleEvent;
|
|
73
75
|
tt.publishEvent = delayedPublishEvent;
|
|
74
76
|
tt.publicComponentEvent = delayedPublicComponentEvent;
|
|
75
77
|
tt.callDestroyLifetimeFun = () => {
|
|
@@ -84,20 +86,31 @@ function injectTt(): void {
|
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
async function OnLifecycleEvent([type, data]: [string, any]) {
|
|
89
|
+
function onLifecycleEvent([type, data]: [string, any]) {
|
|
89
90
|
const hasRootRendered = CHILDREN in __root;
|
|
90
91
|
// never called `render(<App/>, __root)`
|
|
91
92
|
// happens if user call `root.render()` async
|
|
92
93
|
if (!hasRootRendered) {
|
|
93
|
-
|
|
94
|
-
delayedLifecycleEvents.push([type, data]);
|
|
94
|
+
delayLifecycleEvent(type, data);
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
if (__PROFILE__) {
|
|
99
99
|
console.profile(`OnLifecycleEvent::${type}`);
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
void onLifecycleEventImpl(type, data);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
lynx.reportError(e as Error);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (__PROFILE__) {
|
|
109
|
+
console.profileEnd();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function onLifecycleEventImpl(type: string, data: any): Promise<void> {
|
|
101
114
|
switch (type) {
|
|
102
115
|
case LifecycleConstant.firstScreen: {
|
|
103
116
|
const { root: lepusSide, refPatch, jsReadyEventIdSwap } = data;
|
|
@@ -118,6 +131,8 @@ async function OnLifecycleEvent([type, data]: [string, any]) {
|
|
|
118
131
|
}
|
|
119
132
|
markTiming(PerformanceTimingKeys.diff_vdom_end);
|
|
120
133
|
|
|
134
|
+
// TODO: It seems `delayedEvents` and `delayedLifecycleEvents` should be merged into one array to ensure the proper order of events.
|
|
135
|
+
flushDelayedLifecycleEvents();
|
|
121
136
|
if (delayedEvents) {
|
|
122
137
|
delayedEvents.forEach((args) => {
|
|
123
138
|
const [handlerName, data] = args;
|
|
@@ -131,6 +146,7 @@ async function OnLifecycleEvent([type, data]: [string, any]) {
|
|
|
131
146
|
});
|
|
132
147
|
delayedEvents.length = 0;
|
|
133
148
|
}
|
|
149
|
+
|
|
134
150
|
lynxCoreInject.tt.publishEvent = publishEvent;
|
|
135
151
|
lynxCoreInject.tt.publicComponentEvent = publicComponentEvent;
|
|
136
152
|
|
|
@@ -177,19 +193,12 @@ async function OnLifecycleEvent([type, data]: [string, any]) {
|
|
|
177
193
|
break;
|
|
178
194
|
}
|
|
179
195
|
}
|
|
180
|
-
if (__PROFILE__) {
|
|
181
|
-
console.profileEnd();
|
|
182
|
-
}
|
|
183
196
|
}
|
|
184
197
|
|
|
185
198
|
function flushDelayedLifecycleEvents(): void {
|
|
186
199
|
if (delayedLifecycleEvents) {
|
|
187
200
|
delayedLifecycleEvents.forEach((e) => {
|
|
188
|
-
|
|
189
|
-
OnLifecycleEvent(e);
|
|
190
|
-
} catch (e) {
|
|
191
|
-
lynx.reportError(e as Error);
|
|
192
|
-
}
|
|
201
|
+
onLifecycleEvent(e);
|
|
193
202
|
});
|
|
194
203
|
delayedLifecycleEvents.length = 0;
|
|
195
204
|
}
|
|
@@ -214,12 +223,6 @@ function publicComponentEvent(_componentId: string, handlerName: string, data: u
|
|
|
214
223
|
publishEvent(handlerName, data);
|
|
215
224
|
}
|
|
216
225
|
|
|
217
|
-
let delayedEvents: [handlerName: string, data: unknown][];
|
|
218
|
-
function delayedPublishEvent(handlerName: string, data: unknown) {
|
|
219
|
-
delayedEvents ??= [];
|
|
220
|
-
delayedEvents.push([handlerName, data]);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
226
|
function delayedPublicComponentEvent(_componentId: string, handlerName: string, data: unknown) {
|
|
224
227
|
delayedPublishEvent(handlerName, data);
|
|
225
228
|
}
|
|
@@ -258,4 +261,4 @@ function updateCardData(newData: Record<string, any>, options?: Record<string, a
|
|
|
258
261
|
lynxCoreInject.tt.GlobalEventEmitter.emit('onDataChanged');
|
|
259
262
|
}
|
|
260
263
|
|
|
261
|
-
export { injectTt, flushDelayedLifecycleEvents
|
|
264
|
+
export { injectTt, flushDelayedLifecycleEvents };
|
package/runtime/src/lynx-api.ts
CHANGED
|
@@ -87,12 +87,13 @@ export const root: Root = {
|
|
|
87
87
|
} else {
|
|
88
88
|
__root.__jsx = jsx;
|
|
89
89
|
renderBackground(jsx, __root as any);
|
|
90
|
-
if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {
|
|
91
|
-
|
|
90
|
+
if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {
|
|
91
|
+
// This is for cases where `root.render()` is called asynchronously,
|
|
92
|
+
// `firstScreen` message might have been reached.
|
|
93
|
+
flushDelayedLifecycleEvents();
|
|
94
|
+
} else {
|
|
92
95
|
lynx.getNativeApp().callLepusMethod(LifecycleConstant.jsReady, {});
|
|
93
96
|
}
|
|
94
|
-
|
|
95
|
-
flushDelayedLifecycleEvents();
|
|
96
97
|
}
|
|
97
98
|
},
|
|
98
99
|
registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition): void => {
|
package/runtime/src/snapshot.ts
CHANGED
|
@@ -38,6 +38,11 @@ export function setupPage(page: FiberElement): void {
|
|
|
38
38
|
__pageId = __GetElementUniqueID(page);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
export function clearPage(): void {
|
|
42
|
+
__page = undefined as unknown as FiberElement;
|
|
43
|
+
__pageId = 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
export const snapshotManager: {
|
|
42
47
|
values: Map<string, Snapshot>;
|
|
43
48
|
} = {
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import {
|
|
4
|
+
// import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
|
|
5
5
|
|
|
6
|
-
const workletHashSet: Set<string> = /* @__PURE__ */ new Set();
|
|
6
|
+
// const workletHashSet: Set<string> = /* @__PURE__ */ new Set();
|
|
7
7
|
|
|
8
|
+
/* v8 ignore start */
|
|
8
9
|
/**
|
|
9
10
|
* @internal
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
// disable hmr until bugs are fixed
|
|
13
|
+
// TODO: re-enable hmr or change a way to impl it; also need to fix the test case DEV_ONLY_RegisterWorklet
|
|
14
|
+
function registerWorkletOnBackground(_type: string, _hash: string, _fn: Function) {
|
|
15
|
+
// if (workletHashSet.has(hash)) {
|
|
16
|
+
// return;
|
|
17
|
+
// }
|
|
18
|
+
// workletHashSet.add(hash);
|
|
19
|
+
// if (__globalSnapshotPatch) {
|
|
20
|
+
// __globalSnapshotPatch.push(
|
|
21
|
+
// SnapshotOperation.DEV_ONLY_RegisterWorklet,
|
|
22
|
+
// hash,
|
|
23
|
+
// // We use `Function.prototype.toString` to serialize the function for Lepus.
|
|
24
|
+
// fn.toString(),
|
|
25
|
+
// );
|
|
26
|
+
// }
|
|
24
27
|
}
|
|
28
|
+
/* v8 ignore stop */
|
|
25
29
|
|
|
26
30
|
export { registerWorkletOnBackground };
|