@lynx-js/react 0.129.4 → 0.129.5
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 +22 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/lynx/env.test.ts +146 -0
- package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +47 -4
- package/runtime/__test__/element-template/native/index.test.ts +9 -9
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +55 -2
- package/runtime/__test__/element-template/native/reload.test.ts +15 -5
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +1 -1
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +1 -1
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +33 -0
- package/runtime/__test__/element-template/vitest.config.ts +1 -1
- package/runtime/__test__/snapshot/debug/profile.test.jsx +147 -26
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +54 -0
- package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +98 -6
- package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +214 -9
- package/runtime/__test__/snapshot/lynx/suspense.test.jsx +48 -0
- package/runtime/__test__/snapshot/utils/envManager.ts +2 -0
- package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +21 -0
- package/runtime/__test__/worklet-runtime/lifecycle.test.js +297 -0
- package/runtime/__test__/worklet-runtime/profile.test.js +12 -6
- package/runtime/lazy/element-template-internal.js +1 -0
- package/runtime/lib/core/compat/componentIs.d.ts +1 -0
- package/runtime/lib/core/compat/componentIs.js +20 -0
- package/runtime/lib/core/compat/componentIs.js.map +1 -0
- package/runtime/lib/core/lynx/env.d.ts +1 -0
- package/runtime/lib/{element-template → core}/lynx/env.js +3 -2
- package/runtime/lib/core/lynx/env.js.map +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.d.ts +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.js +4 -1
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/element-template/background/commit-event.d.ts +6 -0
- package/runtime/lib/element-template/background/commit-event.js +36 -0
- package/runtime/lib/element-template/background/commit-event.js.map +1 -0
- package/runtime/lib/element-template/background/commit-hook.js +3 -23
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +1 -1
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +1 -2
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +5 -25
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.js +4 -4
- package/runtime/lib/element-template/background/main-thread-function.js.map +1 -0
- package/runtime/lib/element-template/index.d.ts +1 -1
- package/runtime/lib/element-template/index.js +1 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.js +3 -0
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +2 -2
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.d.ts +2 -1
- package/runtime/lib/element-template/native/mts-destroy.js +15 -4
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +2 -2
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +4 -11
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.d.ts +1 -1
- package/runtime/lib/element-template/runtime/template/handle.js +2 -2
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.d.ts +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +7 -2
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/internal.js +4 -10
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +27 -62
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js +2 -2
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lynx/env.js +2 -32
- package/runtime/lib/snapshot/lynx/env.js.map +1 -1
- package/runtime/lib/snapshot/transfer.d.ts +6 -0
- package/runtime/lib/snapshot/transfer.js +154 -11
- package/runtime/lib/snapshot/transfer.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/lifecycle.d.ts +19 -0
- package/runtime/lib/worklet-runtime/bindings/lifecycle.js +49 -0
- package/runtime/lib/worklet-runtime/bindings/lifecycle.js.map +1 -0
- package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +1 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js +9 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/profile.js +1 -3
- package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
- package/runtime/src/core/compat/componentIs.ts +32 -0
- package/runtime/src/{element-template → core}/lynx/env.ts +6 -4
- package/runtime/src/core/thread-function-call/main-thread.ts +5 -1
- package/runtime/src/element-template/background/commit-event.ts +52 -0
- package/runtime/src/element-template/background/commit-hook.ts +4 -31
- package/runtime/src/element-template/background/destroy.ts +1 -1
- package/runtime/src/element-template/background/hydrate.ts +5 -3
- package/runtime/src/element-template/background/hydration-listener.ts +7 -32
- package/runtime/src/element-template/{runtime/template → background}/main-thread-function.ts +4 -7
- package/runtime/src/element-template/index.ts +1 -1
- package/runtime/src/element-template/internal.ts +4 -0
- package/runtime/src/element-template/native/index.ts +2 -2
- package/runtime/src/element-template/native/mts-destroy.ts +21 -4
- package/runtime/src/element-template/native/reload-main-thread.ts +2 -2
- package/runtime/src/element-template/runtime/patch.ts +20 -35
- package/runtime/src/element-template/runtime/template/handle.ts +2 -0
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -2
- package/runtime/src/internal.ts +4 -13
- package/runtime/src/snapshot/debug/profileHooks.ts +30 -91
- package/runtime/src/snapshot/lifecycle/reload.ts +2 -3
- package/runtime/src/snapshot/lynx/env.ts +3 -43
- package/runtime/src/snapshot/transfer.ts +169 -13
- package/runtime/src/worklet-runtime/bindings/lifecycle.ts +51 -0
- package/runtime/src/worklet-runtime/delayWorkletEvent.ts +10 -2
- package/runtime/src/worklet-runtime/utils/profile.ts +1 -3
- package/runtime/types/internal-preact.d.ts +2 -0
- package/runtime/vitest.config.ts +0 -1
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/events.test.jsx +1 -1
- package/testing-library/src/fire-event.ts +1 -1
- package/transform/.turbo/turbo-build$colon$wasm.log +67 -66
- package/transform/__test__/fixture.spec.js +1 -1
- package/transform/cjs/browser.cjs +11 -0
- package/transform/crates/swc_plugin_compat/lib.rs +20 -2
- package/transform/crates/swc_plugin_compat/napi.rs +7 -0
- package/transform/crates/swc_plugin_dynamic_import/lib.rs +15 -4
- package/transform/crates/swc_plugin_element_template/attr_name.rs +0 -3
- package/transform/crates/swc_plugin_element_template/extractor.rs +0 -8
- package/transform/crates/swc_plugin_element_template/lib.rs +12 -1
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +35 -0
- package/transform/crates/swc_plugin_worklet/lib.rs +11 -7
- package/transform/dist/wasm.cjs +1 -1
- package/transform/rspack-napi/lib/index.js +1 -4
- package/transform/rspack-napi/lib/index.js.map +1 -1
- package/transform/rspack-napi/src/index.ts +1 -4
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/lib.rs +394 -27
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +413 -105
- package/transform/swc-plugin-reactlynx/src/lib.rs +99 -22
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +28 -359
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/runtime/__test__/element-template/lynx/env.test.ts +0 -242
- package/runtime/lib/element-template/lynx/env.d.ts +0 -1
- package/runtime/lib/element-template/lynx/env.js.map +0 -1
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +0 -1
- package/runtime/lib/snapshot/compat/componentIs.d.ts +0 -4
- package/runtime/lib/snapshot/compat/componentIs.js +0 -20
- package/runtime/lib/snapshot/compat/componentIs.js.map +0 -1
- package/runtime/src/snapshot/compat/componentIs.ts +0 -30
- /package/runtime/__test__/element-template/runtime/{template → background}/main-thread-function.test.ts +0 -0
- /package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.d.ts +0 -0
|
@@ -2,45 +2,10 @@
|
|
|
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
4
|
import { Component, options } from 'preact';
|
|
5
|
-
import { BITS, COMMIT, COMPONENT, COMPONENT_DIRTY, DIFF, DIFF2, DIFFED, HOOKS, LIST,
|
|
5
|
+
import { BITS, COMMIT, COMPONENT, COMPONENT_DIRTY, DIFF, DIFF2, DIFFED, HOOKS, LIST, NEXT_VALUE, RENDER, VNODE, } from '../../shared/render-constants.js';
|
|
6
6
|
import { getDisplayName } from '../../shared/utils.js';
|
|
7
7
|
import { globalPatchOptions } from '../lifecycle/patch/commit.js';
|
|
8
8
|
import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
|
|
9
|
-
const format = (val) => {
|
|
10
|
-
if (typeof val === 'function') {
|
|
11
|
-
return val.toString();
|
|
12
|
-
}
|
|
13
|
-
return val;
|
|
14
|
-
};
|
|
15
|
-
function safeJsonStringify(val) {
|
|
16
|
-
const seen = new WeakSet();
|
|
17
|
-
return JSON.stringify(val, function (_key, value) {
|
|
18
|
-
if (typeof value === 'object' && value !== null) {
|
|
19
|
-
if (seen.has(value)) {
|
|
20
|
-
return '[Unserializable: Circular]';
|
|
21
|
-
}
|
|
22
|
-
seen.add(value);
|
|
23
|
-
}
|
|
24
|
-
return value;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function buildSetStateProfileMarkArgs(type, currentState, nextState) {
|
|
28
|
-
const EMPTY_OBJ = {};
|
|
29
|
-
const currentStateObj = (currentState ?? EMPTY_OBJ);
|
|
30
|
-
const nextStateObj = (nextState ?? EMPTY_OBJ);
|
|
31
|
-
return {
|
|
32
|
-
componentName: (type && typeof type === 'function')
|
|
33
|
-
? getDisplayName(type)
|
|
34
|
-
: 'Unknown',
|
|
35
|
-
'current state keys': JSON.stringify(Object.keys(currentStateObj)),
|
|
36
|
-
'next state keys': JSON.stringify(Object.keys(nextStateObj)),
|
|
37
|
-
'changed (shallow diff) state keys': JSON.stringify(
|
|
38
|
-
// the setState is in assign manner, we assume nextState is a superset of currentState
|
|
39
|
-
Object.keys(nextStateObj).filter(key => currentStateObj[key] !== nextStateObj[key])),
|
|
40
|
-
currentValue: safeJsonStringify(format(currentState)),
|
|
41
|
-
nextValue: safeJsonStringify(format(nextState)),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
9
|
export function initProfileHook() {
|
|
45
10
|
// early-exit if required profiling APIs are unavailable
|
|
46
11
|
let p;
|
|
@@ -62,21 +27,35 @@ export function initProfileHook() {
|
|
|
62
27
|
// This allows us to trace the flow of its diffing, committing and patching.
|
|
63
28
|
{
|
|
64
29
|
const sFlowID = Symbol('FLOW_ID');
|
|
30
|
+
function markSetState(component, hookIdx) {
|
|
31
|
+
try {
|
|
32
|
+
const type = component[VNODE].type;
|
|
33
|
+
if (hookIdx === undefined
|
|
34
|
+
&& !(typeof type === 'function' && ('prototype' in type) && ('render' in type.prototype))) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// Update traces describe the framework's work without inspecting application state.
|
|
38
|
+
const args = {
|
|
39
|
+
componentName: typeof type === 'function' ? getDisplayName(type) : 'Unknown',
|
|
40
|
+
};
|
|
41
|
+
if (hookIdx !== undefined) {
|
|
42
|
+
args['hookIdx'] = String(hookIdx);
|
|
43
|
+
}
|
|
44
|
+
const flowId = component[sFlowID] ?? profileFlowId();
|
|
45
|
+
profileMark(hookIdx === undefined ? 'ReactLynx::setState' : 'ReactLynx::hooks::setState', { flowId, args });
|
|
46
|
+
component[sFlowID] = flowId;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// A profiling failure must not interrupt Preact's update or scheduling.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
65
52
|
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
66
53
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
67
54
|
const oldSetState = Component.prototype.setState;
|
|
68
55
|
Component.prototype.setState = function (state, callback) {
|
|
69
56
|
oldSetState?.call(this, state, callback);
|
|
70
57
|
if (this[BITS] & COMPONENT_DIRTY) {
|
|
71
|
-
|
|
72
|
-
const isClassComponent = typeof type === 'function' && ('prototype' in type)
|
|
73
|
-
&& ('render' in type.prototype);
|
|
74
|
-
if (isClassComponent) {
|
|
75
|
-
profileMark('ReactLynx::setState', {
|
|
76
|
-
flowId: this[sFlowID] ??= profileFlowId(),
|
|
77
|
-
args: buildSetStateProfileMarkArgs(type, this.state, this[NEXT_STATE]),
|
|
78
|
-
});
|
|
79
|
-
}
|
|
58
|
+
markSetState(this);
|
|
80
59
|
}
|
|
81
60
|
};
|
|
82
61
|
}
|
|
@@ -117,27 +96,13 @@ export function initProfileHook() {
|
|
|
117
96
|
Object.defineProperty(hookState, NEXT_VALUE, {
|
|
118
97
|
get: () => hookState['internalNextValue'],
|
|
119
98
|
set: (value) => {
|
|
99
|
+
hookState['internalNextValue'] = value;
|
|
120
100
|
if (Array.isArray(value)) {
|
|
121
|
-
// hookState[VALUE] is [state, dispatch]
|
|
122
|
-
const currentValueTuple = hookState[VALUE];
|
|
123
|
-
const currentValue = currentValueTuple[0];
|
|
124
|
-
const [nextValue] = value;
|
|
125
101
|
const component = hookState[COMPONENT];
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
return;
|
|
102
|
+
if (component) {
|
|
103
|
+
markSetState(component, hookIdx);
|
|
129
104
|
}
|
|
130
|
-
const type = component[VNODE].type;
|
|
131
|
-
const flowId = component[sFlowID] ??= profileFlowId();
|
|
132
|
-
profileMark('ReactLynx::hooks::setState', {
|
|
133
|
-
flowId,
|
|
134
|
-
args: {
|
|
135
|
-
hookIdx: String(hookIdx),
|
|
136
|
-
...buildSetStateProfileMarkArgs(type, currentValue, nextValue),
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
105
|
}
|
|
140
|
-
hookState['internalNextValue'] = value;
|
|
141
106
|
},
|
|
142
107
|
configurable: true,
|
|
143
108
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profileHooks.js","sourceRoot":"","sources":["../../../src/snapshot/debug/profileHooks.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAK5C,OAAO,EACL,IAAI,EACJ,MAAM,EACN,SAAS,EACT,eAAe,EACf,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,KAAK,EACL,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,MAAM,MAAM,GAAG,CAAC,GAAY,EAAE,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AAE,EAAE;YACtC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,qBAAqB,EAAE,CAAC;gBAC9D,KAAK,CAAC,YAAY,CAAC,GAAG,qBAAqB,CAAC,MAAM,CAAC;YACrD,CAAC;YACD,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC;QAEF,6DAA6D;QAC7D,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,KAAmB,EAAE,EAAE;YACxC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACrC,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;gBACxC,OAAO,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC3B,IAAI,qBAAqB,IAAI,WAAW,KAAK,qBAAqB,CAAC,MAAM,EAAE,CAAC;oBAC1E,2CAA2C;oBAC3C,WAAW,CAAC,8BAA8B,EAAE;wBAC1C,IAAI,EAAE;4BACJ,aAAa,EAAE,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,IAAsB,CAAC;yBAC9E;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { Component, options } from 'preact';\nimport type { ComponentClass, ComponentType, VNode } from 'preact';\n\nimport type { TraceOption } from '@lynx-js/types';\n\nimport {\n BITS,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n HOOKS,\n LIST,\n NEXT_STATE,\n NEXT_VALUE,\n RENDER,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../shared/utils.js';\nimport { globalPatchOptions } from '../lifecycle/patch/commit.js';\nimport { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';\n\nconst format = (val: unknown) => {\n if (typeof val === 'function') {\n return val.toString();\n }\n return val;\n};\n\nfunction safeJsonStringify(val: unknown) {\n const seen = new WeakSet<object>();\n\n return JSON.stringify(val, function(_key, value: unknown) {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return '[Unserializable: Circular]';\n }\n seen.add(value);\n }\n\n return value;\n });\n}\n\nfunction buildSetStateProfileMarkArgs(\n type: string | ComponentType | undefined,\n currentState: unknown,\n nextState: unknown,\n): Record<string, string> {\n const EMPTY_OBJ = {};\n\n const currentStateObj = (currentState ?? EMPTY_OBJ) as Record<string, unknown>;\n const nextStateObj = (nextState ?? EMPTY_OBJ) as Record<string, unknown>;\n\n return {\n componentName: (type && typeof type === 'function')\n ? getDisplayName(type as ComponentClass)\n : 'Unknown',\n 'current state keys': JSON.stringify(Object.keys(currentStateObj)),\n 'next state keys': JSON.stringify(Object.keys(nextStateObj)),\n 'changed (shallow diff) state keys': JSON.stringify(\n // the setState is in assign manner, we assume nextState is a superset of currentState\n Object.keys(nextStateObj).filter(\n key => currentStateObj[key] !== nextStateObj[key],\n ),\n ),\n currentValue: safeJsonStringify(format(currentState)),\n nextValue: safeJsonStringify(format(nextState)),\n };\n}\n\nexport function initProfileHook(): void {\n // early-exit if required profiling APIs are unavailable\n let p;\n /* v8 ignore start */\n if (\n !(p = lynx.performance)\n || typeof p.profileStart !== 'function'\n || typeof p.profileEnd !== 'function'\n || typeof p.profileMark !== 'function'\n || typeof p.profileFlowId !== 'function'\n ) {\n return;\n }\n /* v8 ignore stop */\n\n const profileStart = p.profileStart.bind(p);\n const profileEnd = p.profileEnd.bind(p);\n const profileMark = p.profileMark.bind(p);\n const profileFlowId = p.profileFlowId.bind(p);\n\n // for each setState call, we will add a profiling trace and\n // attach a flowId to the component instance.\n // This allows us to trace the flow of its diffing, committing and patching.\n {\n const sFlowID = Symbol('FLOW_ID');\n type PatchedComponent = Component & { [sFlowID]?: number };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldSetState = Component.prototype.setState;\n Component.prototype.setState = function(this: PatchedComponent & { [NEXT_STATE]: unknown }, state, callback) {\n oldSetState?.call(this, state, callback);\n\n if (this[BITS] & COMPONENT_DIRTY) {\n const type = this[VNODE]!.type;\n const isClassComponent = typeof type === 'function' && ('prototype' in type)\n && ('render' in type.prototype);\n\n if (isClassComponent) {\n profileMark('ReactLynx::setState', {\n flowId: this[sFlowID] ??= profileFlowId(),\n args: buildSetStateProfileMarkArgs(\n type,\n this.state,\n this[NEXT_STATE],\n ),\n });\n }\n }\n };\n }\n\n // These hot callbacks have fixed signatures; avoid collecting and spreading\n // an argument array for every host and component visited.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff2 = options[DIFF2];\n options[DIFF2] = (vnode, oldVNode) => {\n // We only add profiling trace for Component\n if (typeof vnode.type === 'function') {\n const profileOptions: TraceOption = {};\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const c: PatchedComponent = oldVNode[COMPONENT]!;\n if (c) {\n const flowId = c[sFlowID];\n delete c[sFlowID];\n if (flowId) {\n globalPatchOptions.flowIds ??= [];\n globalPatchOptions.flowIds.push(flowId);\n profileOptions.flowId = flowId;\n }\n }\n }\n\n profileStart(\n `ReactLynx::diff::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`,\n profileOptions,\n );\n }\n oldDiff2?.(vnode, oldVNode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiffed = options[DIFFED];\n options[DIFFED] = vnode => {\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const hooks = vnode[COMPONENT]?.[HOOKS];\n const hookList = hooks?.[LIST];\n\n if (Array.isArray(hookList)) {\n hookList.forEach((hookState, hookIdx: number) => {\n hookState['internalNextValue'] = hookState[NEXT_VALUE];\n // define a setter for __N to track the next value of the hook\n Object.defineProperty(hookState, NEXT_VALUE, {\n get: () => hookState['internalNextValue'],\n set: (value) => {\n if (Array.isArray(value)) {\n // hookState[VALUE] is [state, dispatch]\n const currentValueTuple = hookState[VALUE] as unknown[];\n const currentValue = currentValueTuple[0];\n const [nextValue] = value as unknown[];\n\n const component = hookState[COMPONENT] as PatchedComponent | undefined;\n if (!component) {\n hookState['internalNextValue'] = value;\n return;\n }\n\n const type = component[VNODE]!.type;\n const flowId = component[sFlowID] ??= profileFlowId();\n\n profileMark('ReactLynx::hooks::setState', {\n flowId,\n args: {\n hookIdx: String(hookIdx),\n ...buildSetStateProfileMarkArgs(\n type,\n currentValue,\n nextValue,\n ),\n },\n });\n }\n hookState['internalNextValue'] = value;\n },\n configurable: true,\n });\n });\n }\n }\n\n if (typeof vnode.type === 'function') {\n profileEnd(); // for options[DIFF2]\n }\n oldDiffed?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldCommit = options[COMMIT];\n options[COMMIT] = (vnode, commitQueue) => {\n profileStart('ReactLynx::commit', {\n ...globalPatchOptions.flowIds\n ? {\n flowId: globalPatchOptions.flowIds[0],\n flowIds: globalPatchOptions.flowIds,\n }\n : {},\n });\n oldCommit?.(vnode, commitQueue);\n profileEnd();\n };\n }\n }\n\n // Profile the user-provided `render`.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldRender = options[RENDER];\n options[RENDER] = (vnode: VNode) => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalRender = vnode[COMPONENT]!.render;\n vnode[COMPONENT]!.render = function render(this, props, state, context) {\n profileStart(`ReactLynx::render::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`);\n try {\n return originalRender.call(this, props, state, context);\n } finally {\n profileEnd();\n vnode[COMPONENT]!.render = originalRender;\n }\n };\n oldRender?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const sPatchLength = Symbol('PATCH_LENGTH');\n\n type PatchedVNode = VNode & { [sPatchLength]?: number };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff = options[DIFF];\n options[DIFF] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function' && __globalSnapshotPatch) {\n vnode[sPatchLength] = __globalSnapshotPatch.length;\n }\n oldDiff?.(vnode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldPatchDiffed = options[DIFFED];\n options[DIFFED] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function') {\n const patchLength = vnode[sPatchLength];\n delete vnode[sPatchLength];\n if (__globalSnapshotPatch && patchLength === __globalSnapshotPatch.length) {\n // \"NoPatch\" is a conventional name in Lynx\n profileMark('ReactLynx::diffFinishNoPatch', {\n args: {\n componentName: /* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass),\n },\n });\n }\n }\n oldPatchDiffed?.(vnode);\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profileHooks.js","sourceRoot":"","sources":["../../../src/snapshot/debug/profileHooks.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAK5C,OAAO,EACL,IAAI,EACJ,MAAM,EACN,SAAS,EACT,eAAe,EACf,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,UAAU,EACV,MAAM,EACN,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,MAAM,UAAU,eAAe;I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AAO,CAAC,MAAM,CAAC,GAAG,CAAC,KAAmB,EAAE,EAAE;YACxC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACrC,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;gBACxC,OAAO,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC3B,IAAI,qBAAqB,IAAI,WAAW,KAAK,qBAAqB,CAAC,MAAM,EAAE,CAAC;oBAC1E,2CAA2C;oBAC3C,WAAW,CAAC,8BAA8B,EAAE;wBAC1C,IAAI,EAAE;4BACJ,aAAa,EAAE,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,IAAsB,CAAC;yBAC9E;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { Component, options } from 'preact';\nimport type { ComponentClass, VNode } from 'preact';\n\nimport type { TraceOption } from '@lynx-js/types';\n\nimport {\n BITS,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n HOOKS,\n LIST,\n NEXT_VALUE,\n RENDER,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../shared/utils.js';\nimport { globalPatchOptions } from '../lifecycle/patch/commit.js';\nimport { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';\n\nexport function initProfileHook(): void {\n // early-exit if required profiling APIs are unavailable\n let p;\n /* v8 ignore start */\n if (\n !(p = lynx.performance)\n || typeof p.profileStart !== 'function'\n || typeof p.profileEnd !== 'function'\n || typeof p.profileMark !== 'function'\n || typeof p.profileFlowId !== 'function'\n ) {\n return;\n }\n /* v8 ignore stop */\n\n const profileStart = p.profileStart.bind(p);\n const profileEnd = p.profileEnd.bind(p);\n const profileMark = p.profileMark.bind(p);\n const profileFlowId = p.profileFlowId.bind(p);\n\n // for each setState call, we will add a profiling trace and\n // attach a flowId to the component instance.\n // This allows us to trace the flow of its diffing, committing and patching.\n {\n const sFlowID = Symbol('FLOW_ID');\n type PatchedComponent = Component & { [sFlowID]?: number };\n\n function markSetState(component: PatchedComponent, hookIdx?: number): void {\n try {\n const type = component[VNODE]!.type;\n if (\n hookIdx === undefined\n && !(typeof type === 'function' && ('prototype' in type) && ('render' in type.prototype))\n ) {\n return;\n }\n // Update traces describe the framework's work without inspecting application state.\n const args: Record<string, string> = {\n componentName: typeof type === 'function' ? getDisplayName(type as ComponentClass) : 'Unknown',\n };\n if (hookIdx !== undefined) {\n args['hookIdx'] = String(hookIdx);\n }\n const flowId = component[sFlowID] ?? profileFlowId();\n profileMark(hookIdx === undefined ? 'ReactLynx::setState' : 'ReactLynx::hooks::setState', { flowId, args });\n component[sFlowID] = flowId;\n } catch {\n // A profiling failure must not interrupt Preact's update or scheduling.\n }\n }\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldSetState = Component.prototype.setState;\n Component.prototype.setState = function(this: PatchedComponent, state, callback) {\n oldSetState?.call(this, state, callback);\n\n if (this[BITS] & COMPONENT_DIRTY) {\n markSetState(this);\n }\n };\n }\n\n // These hot callbacks have fixed signatures; avoid collecting and spreading\n // an argument array for every host and component visited.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff2 = options[DIFF2];\n options[DIFF2] = (vnode, oldVNode) => {\n // We only add profiling trace for Component\n if (typeof vnode.type === 'function') {\n const profileOptions: TraceOption = {};\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const c: PatchedComponent = oldVNode[COMPONENT]!;\n if (c) {\n const flowId = c[sFlowID];\n delete c[sFlowID];\n if (flowId) {\n globalPatchOptions.flowIds ??= [];\n globalPatchOptions.flowIds.push(flowId);\n profileOptions.flowId = flowId;\n }\n }\n }\n\n profileStart(\n `ReactLynx::diff::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`,\n profileOptions,\n );\n }\n oldDiff2?.(vnode, oldVNode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiffed = options[DIFFED];\n options[DIFFED] = vnode => {\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const hooks = vnode[COMPONENT]?.[HOOKS];\n const hookList = hooks?.[LIST];\n\n if (Array.isArray(hookList)) {\n hookList.forEach((hookState, hookIdx: number) => {\n hookState['internalNextValue'] = hookState[NEXT_VALUE];\n // define a setter for __N to track the next value of the hook\n Object.defineProperty(hookState, NEXT_VALUE, {\n get: () => hookState['internalNextValue'],\n set: (value) => {\n hookState['internalNextValue'] = value;\n if (Array.isArray(value)) {\n const component = hookState[COMPONENT] as PatchedComponent | undefined;\n if (component) {\n markSetState(component, hookIdx);\n }\n }\n },\n configurable: true,\n });\n });\n }\n }\n\n if (typeof vnode.type === 'function') {\n profileEnd(); // for options[DIFF2]\n }\n oldDiffed?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldCommit = options[COMMIT];\n options[COMMIT] = (vnode, commitQueue) => {\n profileStart('ReactLynx::commit', {\n ...globalPatchOptions.flowIds\n ? {\n flowId: globalPatchOptions.flowIds[0],\n flowIds: globalPatchOptions.flowIds,\n }\n : {},\n });\n oldCommit?.(vnode, commitQueue);\n profileEnd();\n };\n }\n }\n\n // Profile the user-provided `render`.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldRender = options[RENDER];\n options[RENDER] = (vnode: VNode) => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalRender = vnode[COMPONENT]!.render;\n vnode[COMPONENT]!.render = function render(this, props, state, context) {\n profileStart(`ReactLynx::render::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`);\n try {\n return originalRender.call(this, props, state, context);\n } finally {\n profileEnd();\n vnode[COMPONENT]!.render = originalRender;\n }\n };\n oldRender?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const sPatchLength = Symbol('PATCH_LENGTH');\n\n type PatchedVNode = VNode & { [sPatchLength]?: number };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff = options[DIFF];\n options[DIFF] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function' && __globalSnapshotPatch) {\n vnode[sPatchLength] = __globalSnapshotPatch.length;\n }\n oldDiff?.(vnode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldPatchDiffed = options[DIFFED];\n options[DIFFED] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function') {\n const patchLength = vnode[sPatchLength];\n delete vnode[sPatchLength];\n if (__globalSnapshotPatch && patchLength === __globalSnapshotPatch.length) {\n // \"NoPatch\" is a conventional name in Lynx\n profileMark('ReactLynx::diffFinishNoPatch', {\n args: {\n componentName: /* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass),\n },\n });\n }\n }\n oldPatchDiffed?.(vnode);\n };\n }\n}\n"]}
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* and background thread.
|
|
7
7
|
*/
|
|
8
8
|
import { render } from 'preact';
|
|
9
|
-
import { clearDelayedRunOnBackgroundFunctions } from '@lynx-js/react/worklet-runtime/bindings';
|
|
10
9
|
import { destroyBackground } from './destroy.js';
|
|
11
10
|
import { renderMainThread } from './render.js';
|
|
12
11
|
import { canReEvalBackgroundEntry, canReEvalMainThreadEntry, installMainThreadReloadCompleter, reEvalBackgroundEntry, reEvalMainThreadEntry, } from '../../core/entry-reload.js';
|
|
@@ -15,6 +14,7 @@ import { resetFunctionCallReturnListener } from '../../core/thread-function-call
|
|
|
15
14
|
import { __root, setRoot } from '../../root.js';
|
|
16
15
|
import { profileEnd, profileStart } from '../../shared/profile.js';
|
|
17
16
|
import { isEmptyObject } from '../../shared/utils.js';
|
|
17
|
+
import { resetWorkletRuntimeForReload } from '../../worklet-runtime/bindings/lifecycle.js';
|
|
18
18
|
import { LifecycleConstant } from '../lifecycle/constant.js';
|
|
19
19
|
import { __pendingListUpdates } from '../list/pendingListUpdates.js';
|
|
20
20
|
import { hydrate } from '../renderToOpcodes/hydrate.js';
|
|
@@ -27,7 +27,7 @@ function reloadMainThread(data, options) {
|
|
|
27
27
|
if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
|
|
28
28
|
profileStart('ReactLynx::reloadMainThread');
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
resetWorkletRuntimeForReload();
|
|
31
31
|
resetFunctionCallReturnListener();
|
|
32
32
|
increaseReloadVersion();
|
|
33
33
|
if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reload.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"reload.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,gCAAgC,EAChC,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,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IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,UAA+B,EAAE,OAAiC;IAC1F,IAAI,wBAAwB,EAAE,EAAE,CAAC;QAC/B,qBAAqB,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE;YAC9C,kEAAkE;YAClE,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAC9C,CAAC;IAED,iBAAiB,EAAE,CAAC;IACpB,qBAAqB,EAAE,CAAC;IAExB,2EAA2E;IAC3E,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEjE,gBAAgB,CAAC,KAAK,GAAG,IAAI,CAAC;IAC9B,iEAAiE;IACjE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAa,CAAC,CAAC;IAEpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the reload (thinking of \"refresh\" in browser) for both main thread\n * and background thread.\n */\n\nimport { render } from 'preact';\n\nimport { destroyBackground } from './destroy.js';\nimport { renderMainThread } from './render.js';\nimport {\n canReEvalBackgroundEntry,\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalBackgroundEntry,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';\nimport { __root, setRoot } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { isEmptyObject } from '../../shared/utils.js';\nimport { resetWorkletRuntimeForReload } from '../../worklet-runtime/bindings/lifecycle.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { __page, setupPage } from '../snapshot/definition.js';\nimport { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\nimport { clearFirstScreenEventIdSwap, firstScreenSync } from './event/firstScreenSync.js';\nimport { shouldDelayUiOps } from './ref/delay.js';\n\nfunction reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n resetWorkletRuntimeForReload();\n resetFunctionCallReturnListener();\n increaseReloadVersion();\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n Object.assign(lynx.__initData, data);\n }\n\n snapshotInstanceManager.clear();\n __pendingListUpdates.clearAttachedLists();\n clearFirstScreenEventIdSwap();\n\n const oldRoot = __root;\n if (canReEvalMainThreadEntry()) {\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ oldRoot: oldRoot as SnapshotInstance, page: __page, options });\n return;\n }\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n finishMainThreadReload(oldRoot as SnapshotInstance, options);\n}\n\ninterface MainThreadReloadHandoff {\n oldRoot: SnapshotInstance;\n page: FiberElement;\n options: UpdatePageOption;\n}\n\nfunction completeMainThreadReload({ oldRoot, page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n finishMainThreadReload(oldRoot, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction finishMainThreadReload(oldRoot: SnapshotInstance, options: UpdatePageOption): void {\n renderMainThread();\n hydrate(oldRoot, __root as SnapshotInstance, {\n skipUnRef: true,\n });\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n\n if (firstScreenSync.isSynced) {\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root: JSON.stringify(__root),\n },\n ]);\n }\n\n __FlushElementTree(__page, options);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nfunction reloadBackground(updateData: Record<string, any>, options?: Record<string, unknown>): void {\n if (canReEvalBackgroundEntry()) {\n reEvalBackgroundEntry(updateData, options, () => {\n // A queued `updateGlobalProps` callback must not render it again.\n __root.__jsx = undefined;\n });\n return;\n }\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadBackground');\n }\n\n destroyBackground();\n increaseReloadVersion();\n\n // COW when modify `lynx.__initData` to make sure Provider & Consumer works\n lynx.__initData = Object.assign({}, lynx.__initData, updateData);\n\n shouldDelayUiOps.value = true;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(__root.__jsx, __root as any);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { completeMainThreadReload, reloadBackground, reloadMainThread };\n"]}
|
|
@@ -1,46 +1,16 @@
|
|
|
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 { setupSharedLynxEnv } from '../../core/lynx/env.js';
|
|
5
5
|
export function setupLynxEnv() {
|
|
6
|
-
|
|
7
|
-
const { initData, updateData } = lynx.getApp()._params;
|
|
8
|
-
lynx.__initData = { ...initData, ...updateData };
|
|
9
|
-
lynx.registerDataProcessors = function () { };
|
|
10
|
-
}
|
|
6
|
+
setupSharedLynxEnv();
|
|
11
7
|
if (__LEPUS__) {
|
|
12
|
-
lynx.__initData = {
|
|
13
|
-
/* available only in renderPage */
|
|
14
|
-
};
|
|
15
|
-
// @ts-expect-error no type for lynx.SystemInfo
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
17
|
-
globalThis.SystemInfo = lynx.SystemInfo ?? {};
|
|
18
8
|
lynx.reportError = function (e) {
|
|
19
9
|
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
|
|
20
10
|
_ReportError(error, {
|
|
21
11
|
errorCode: 1101, // ErrCode::LYNX_ERROR_CODE_LEPUS in Lynx/base/debug/error_code.h
|
|
22
12
|
});
|
|
23
13
|
};
|
|
24
|
-
lynx.triggerGlobalEventFromLepus = function (eventName, params) {
|
|
25
|
-
__OnLifecycleEvent(['globalEventFromLepus', [eventName, params]]);
|
|
26
|
-
};
|
|
27
|
-
{
|
|
28
|
-
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
29
|
-
function __name(empty) {
|
|
30
|
-
return `Native${empty}Modules`;
|
|
31
|
-
}
|
|
32
|
-
// TODO(hongzhiyuan.hzy): make sure this is run before any other code (especially code access `NativeModules`)
|
|
33
|
-
// @ts-expect-error hack
|
|
34
|
-
if (typeof globalThis[__name('')] === 'undefined') {
|
|
35
|
-
// @ts-expect-error hack
|
|
36
|
-
globalThis[__name('')] = undefined;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
lynx.registerDataProcessors = function (dataProcessorDefinition) {
|
|
40
|
-
globalThis.processData = createProcessData(dataProcessorDefinition);
|
|
41
|
-
};
|
|
42
|
-
// register empty DataProcessors to make sure `globalThis.processData` is set
|
|
43
|
-
lynx.registerDataProcessors();
|
|
44
14
|
}
|
|
45
15
|
}
|
|
46
16
|
//# sourceMappingURL=env.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/snapshot/lynx/env.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/snapshot/lynx/env.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,UAAU,YAAY;IAC1B,kBAAkB,EAAE,CAAC;IAErB,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,UAAS,CAAiB;YAC3C,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YACpE,YAAY,CAAC,KAAK,EAAE;gBAClB,SAAS,EAAE,IAAI,EAAE,iEAAiE;aACnF,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { setupSharedLynxEnv } from '../../core/lynx/env.js';\n\nexport function setupLynxEnv(): void {\n setupSharedLynxEnv();\n\n if (__LEPUS__) {\n lynx.reportError = function(e: Error | string) {\n const error = e instanceof Error ? e : new Error(JSON.stringify(e));\n _ReportError(error, {\n errorCode: 1101, // ErrCode::LYNX_ERROR_CODE_LEPUS in Lynx/base/debug/error_code.h\n });\n };\n }\n}\n"]}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { ComponentType } from 'preact';
|
|
2
|
+
import type { Worklet } from '../worklet-runtime/bindings/types.js';
|
|
2
3
|
type TransferProps = Record<string, unknown>;
|
|
3
4
|
interface Scope {
|
|
4
5
|
transferId: string;
|
|
5
6
|
}
|
|
6
7
|
type ComponentProvider = (scope: Scope) => ComponentType<TransferProps>;
|
|
8
|
+
export interface PendingMainThreadCall {
|
|
9
|
+
worklet: Worklet;
|
|
10
|
+
params: unknown[];
|
|
11
|
+
resolve: (value: any) => void;
|
|
12
|
+
}
|
|
7
13
|
/**
|
|
8
14
|
* Registers components that native hosts render as independent transfer instances.
|
|
9
15
|
* Registering the first component turns the page into a transfer page, where `root.render` is ignored.
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
// Copyright 2026 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 { createElement, render } from 'preact';
|
|
4
|
+
import { createElement, options, render } from 'preact';
|
|
5
|
+
import { addReloadScopedEventListener } from '../core/reload-scoped-event.js';
|
|
5
6
|
import { getReloadVersion } from '../core/reload-version.js';
|
|
7
|
+
import { prepareMainThreadFunctionCtx } from '../core/thread-function-call/main-thread.js';
|
|
6
8
|
import { __root, enableTransferMode, warnRootRenderOnTransferPage } from '../root.js';
|
|
7
|
-
import { CHILDREN, PARENT } from '../shared/render-constants.js';
|
|
9
|
+
import { CHILDREN, COMMIT, COMPONENT, DIFFED, HOOKS, PARENT, PENDING_EFFECTS, RENDER_COMPONENT, VALUE, } from '../shared/render-constants.js';
|
|
10
|
+
import { isRendering } from './lifecycle/isRendering.js';
|
|
11
|
+
import { WorkletEvents } from '../worklet-runtime/bindings/events.js';
|
|
8
12
|
import { genCommitTaskId, replaceCommitHook } from './lifecycle/patch/commit.js';
|
|
9
13
|
import { updateMainThread } from './lifecycle/patch/updateMainThread.js';
|
|
10
14
|
import { __pendingListUpdates } from './list/pendingListUpdates.js';
|
|
@@ -27,10 +31,14 @@ function initialize() {
|
|
|
27
31
|
const frames = new Map();
|
|
28
32
|
const disposed = new Set();
|
|
29
33
|
const owners = new WeakMap();
|
|
34
|
+
const workletReturns = new Map();
|
|
35
|
+
let nextWorkletReturnId = 0;
|
|
30
36
|
const removers = [];
|
|
37
|
+
const patchedDelays = new WeakSet();
|
|
31
38
|
const pendingCreates = [];
|
|
32
39
|
let pageReady = !mts;
|
|
33
40
|
let active;
|
|
41
|
+
let activeVersion;
|
|
34
42
|
function send(type, data) {
|
|
35
43
|
const target = mts ? lynx.getJSContext() : lynx.getCoreContext();
|
|
36
44
|
target.dispatchEvent({ type, data: JSON.stringify(data) });
|
|
@@ -47,14 +55,17 @@ function initialize() {
|
|
|
47
55
|
target.addEventListener(type, callback);
|
|
48
56
|
removers.push(() => target.removeEventListener(type, callback));
|
|
49
57
|
}
|
|
50
|
-
function withInstance(instance, fn) {
|
|
58
|
+
function withInstance(instance, fn, version = instance?.version) {
|
|
51
59
|
const previous = active;
|
|
60
|
+
const previousVersion = activeVersion;
|
|
52
61
|
active = instance;
|
|
62
|
+
activeVersion = version;
|
|
53
63
|
try {
|
|
54
64
|
return fn();
|
|
55
65
|
}
|
|
56
66
|
finally {
|
|
57
67
|
active = previous;
|
|
68
|
+
activeVersion = previousVersion;
|
|
58
69
|
}
|
|
59
70
|
}
|
|
60
71
|
function findOwner(vnode) {
|
|
@@ -70,6 +81,7 @@ function initialize() {
|
|
|
70
81
|
function renderBackground(instance) {
|
|
71
82
|
const container = instance.background;
|
|
72
83
|
withInstance(instance, () => render(createElement(instance.Component, instance.props), container));
|
|
84
|
+
// Each `render` call creates a new root vnode.
|
|
73
85
|
const vnode = container[CHILDREN];
|
|
74
86
|
if (vnode)
|
|
75
87
|
owners.set(vnode, instance);
|
|
@@ -105,6 +117,11 @@ function initialize() {
|
|
|
105
117
|
}
|
|
106
118
|
/** Releases the commits of an instance that will never be applied. */
|
|
107
119
|
function release(instance) {
|
|
120
|
+
instance.firstFrameWorklets = undefined;
|
|
121
|
+
for (const [id, call] of workletReturns) {
|
|
122
|
+
if (call.instance === instance)
|
|
123
|
+
workletReturns.delete(id);
|
|
124
|
+
}
|
|
108
125
|
instance.inFlight?.finish();
|
|
109
126
|
instance.inFlight = undefined;
|
|
110
127
|
instance.queue.forEach(item => item.finish());
|
|
@@ -142,7 +159,18 @@ function initialize() {
|
|
|
142
159
|
instance.phase = 'hydrating';
|
|
143
160
|
const serialized = JSON.parse(frame.snapshot);
|
|
144
161
|
const snapshotPatch = withInstance(instance, () => hydrate(serialized, instance.background));
|
|
145
|
-
|
|
162
|
+
const patchList = { patchList: [{ id: genCommitTaskId(), snapshotPatch }] };
|
|
163
|
+
if (instance.firstFrameWorklets?.length) {
|
|
164
|
+
patchList.delayedRunOnMainThreadData = instance.firstFrameWorklets.map(({ worklet, params, resolve }) => {
|
|
165
|
+
const callWorklet = { ...worklet };
|
|
166
|
+
prepareMainThreadFunctionCtx(callWorklet);
|
|
167
|
+
const resolveId = --nextWorkletReturnId;
|
|
168
|
+
workletReturns.set(resolveId, { instance, resolve });
|
|
169
|
+
return { worklet: callWorklet, params, resolveId };
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
instance.firstFrameWorklets = undefined;
|
|
173
|
+
enqueue(instance, 'hydrate', patchList, { reloadVersion: getReloadVersion(), isHydration: true }, () => {
|
|
146
174
|
if (instance.phase === 'hydrating')
|
|
147
175
|
instance.phase = 'live';
|
|
148
176
|
});
|
|
@@ -176,6 +204,7 @@ function initialize() {
|
|
|
176
204
|
}
|
|
177
205
|
else {
|
|
178
206
|
instance.background = new BackgroundSnapshotInstance('root');
|
|
207
|
+
instance.firstFrameWorklets = [];
|
|
179
208
|
renderBackground(instance);
|
|
180
209
|
const frame = frames.get(init.transferId);
|
|
181
210
|
if (frame) {
|
|
@@ -184,21 +213,39 @@ function initialize() {
|
|
|
184
213
|
}
|
|
185
214
|
}
|
|
186
215
|
}
|
|
187
|
-
/**
|
|
188
|
-
function
|
|
216
|
+
/** Replaces the props of an instance; returns the instance to re-render, if it has been created. */
|
|
217
|
+
function replaceProps(update) {
|
|
189
218
|
const pending = pendingCreates.find(init => init.transferId === update.transferId);
|
|
190
219
|
if (pending) {
|
|
191
220
|
pending.initialProps = update.props;
|
|
192
|
-
return;
|
|
221
|
+
return undefined;
|
|
193
222
|
}
|
|
194
223
|
const instance = instances.get(update.transferId);
|
|
224
|
+
if (instance)
|
|
225
|
+
instance.props = update.props;
|
|
226
|
+
return instance;
|
|
227
|
+
}
|
|
228
|
+
/** Re-renders the background with the new props and keeps component state, like `updateGlobalProps`. */
|
|
229
|
+
function updateProps(update) {
|
|
230
|
+
const instance = replaceProps(update);
|
|
231
|
+
if (!instance)
|
|
232
|
+
return;
|
|
233
|
+
// The main thread keeps its elements; background commits bring them up to date.
|
|
234
|
+
if (mts) {
|
|
235
|
+
send('__UpdateTransfer', update);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
renderBackground(instance);
|
|
239
|
+
}
|
|
240
|
+
/** Re-renders both threads with the new props and re-syncs the first frame, like a template reload. */
|
|
241
|
+
function reloadProps(update) {
|
|
242
|
+
const instance = replaceProps(update);
|
|
195
243
|
if (!instance)
|
|
196
244
|
return;
|
|
197
|
-
instance.props = update.props;
|
|
198
245
|
instance.version++;
|
|
199
246
|
instance.seq = 0;
|
|
200
247
|
if (mts) {
|
|
201
|
-
send('
|
|
248
|
+
send('__ReloadTransfer', update);
|
|
202
249
|
renderMain(instance);
|
|
203
250
|
return;
|
|
204
251
|
}
|
|
@@ -206,6 +253,7 @@ function initialize() {
|
|
|
206
253
|
instance.phase = 'waiting';
|
|
207
254
|
release(instance);
|
|
208
255
|
withInstance(instance, () => render(null, instance.background));
|
|
256
|
+
instance.firstFrameWorklets = [];
|
|
209
257
|
renderBackground(instance);
|
|
210
258
|
}
|
|
211
259
|
function dispose(scope, notify = true) {
|
|
@@ -240,6 +288,39 @@ function initialize() {
|
|
|
240
288
|
render(null, __root);
|
|
241
289
|
}
|
|
242
290
|
enableTransferMode();
|
|
291
|
+
/**
|
|
292
|
+
* The worklet runtime flushes its pre-hydration `runOnBackground` queue once per page, dropping calls whose
|
|
293
|
+
* first-screen handles are not bound yet. Each transfer instance hydrates separately, so a hydration only runs
|
|
294
|
+
* the calls already bound to the background and keeps the rest in place for the instances still waiting.
|
|
295
|
+
*/
|
|
296
|
+
function keepDelayedBackgroundCalls() {
|
|
297
|
+
const delay = globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl;
|
|
298
|
+
if (!delay || patchedDelays.has(delay))
|
|
299
|
+
return;
|
|
300
|
+
patchedDelays.add(delay);
|
|
301
|
+
/* eslint-disable-next-line @typescript-eslint/unbound-method */
|
|
302
|
+
const run = delay.runDelayedBackgroundFunctions;
|
|
303
|
+
delay.runDelayedBackgroundFunctions = () => {
|
|
304
|
+
const queue = delay.delayedBackgroundFunctionArray;
|
|
305
|
+
if (queue.every(details => !details || details.jsFnHandle)) {
|
|
306
|
+
run();
|
|
307
|
+
// Later instances still queue their first-screen calls.
|
|
308
|
+
delay.hasHydrated = false;
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// Pending handles keep indices into the queue, so bound calls are cleared in place.
|
|
312
|
+
queue.forEach((details, index) => {
|
|
313
|
+
if (!details?.jsFnHandle)
|
|
314
|
+
return;
|
|
315
|
+
queue[index] = undefined;
|
|
316
|
+
details.task(details.jsFnHandle._jsFnId, details.jsFnHandle._execId);
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
removers.push(() => {
|
|
320
|
+
delay.runDelayedBackgroundFunctions = run;
|
|
321
|
+
patchedDelays.delete(delay);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
243
324
|
if (mts) {
|
|
244
325
|
listen(lynx.getEngine(), '__RenderPage', ([initData]) => {
|
|
245
326
|
lynx.__initData = initData ?? {};
|
|
@@ -258,7 +339,8 @@ function initialize() {
|
|
|
258
339
|
});
|
|
259
340
|
const native = lynx.getNative();
|
|
260
341
|
listen(native, '__CreateTransfer', create);
|
|
261
|
-
listen(native, '
|
|
342
|
+
listen(native, '__UpdateTransfer', updateProps);
|
|
343
|
+
listen(native, '__ReloadTransfer', reloadProps);
|
|
262
344
|
listen(native, '__DestroyTransfer', scope => dispose(scope));
|
|
263
345
|
listen(lynx.getJSContext(), '__TransferCommit', packet => {
|
|
264
346
|
const instance = instances.get(packet.transferId);
|
|
@@ -270,6 +352,8 @@ function initialize() {
|
|
|
270
352
|
try {
|
|
271
353
|
if (packet.seq !== instance.seq + 1)
|
|
272
354
|
throw new Error('Transfer commit sequence mismatch');
|
|
355
|
+
if (packet.patchOptions.isHydration)
|
|
356
|
+
keepDelayedBackgroundCalls();
|
|
273
357
|
updateMainThread({ data: JSON.stringify(packet.patchList), patchOptions: packet.patchOptions });
|
|
274
358
|
instance.seq = packet.seq;
|
|
275
359
|
status = 'applied';
|
|
@@ -299,12 +383,71 @@ function initialize() {
|
|
|
299
383
|
}
|
|
300
384
|
enqueue(instance, 'update', patchList, { ...patchOptions, reloadVersion: getReloadVersion() }, finish);
|
|
301
385
|
});
|
|
386
|
+
let rendering;
|
|
387
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
388
|
+
const renderComponent = options[RENDER_COMPONENT];
|
|
389
|
+
const commit = options[COMMIT];
|
|
390
|
+
const diffed = options[DIFFED];
|
|
391
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
392
|
+
options[RENDER_COMPONENT] = (vnode, component) => {
|
|
393
|
+
rendering = findOwner(vnode);
|
|
394
|
+
renderComponent?.(vnode, component);
|
|
395
|
+
};
|
|
396
|
+
options[DIFFED] = vnode => {
|
|
397
|
+
const effects = vnode[COMPONENT]?.[HOOKS]?.[PENDING_EFFECTS];
|
|
398
|
+
if (effects?.length) {
|
|
399
|
+
const instance = findOwner(vnode);
|
|
400
|
+
if (instance?.phase === 'waiting') {
|
|
401
|
+
const version = instance.version;
|
|
402
|
+
for (const effect of effects) {
|
|
403
|
+
const callback = effect[VALUE];
|
|
404
|
+
effect[VALUE] = () => {
|
|
405
|
+
const cleanup = withInstance(instance, () => callback.call(effect), version);
|
|
406
|
+
return typeof cleanup === 'function' ? () => withInstance(instance, cleanup, version) : cleanup;
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
diffed?.(vnode);
|
|
412
|
+
};
|
|
413
|
+
options[COMMIT] = (vnode, queue) => {
|
|
414
|
+
rendering = undefined;
|
|
415
|
+
withInstance(findOwner(vnode), () => commit?.(vnode, queue));
|
|
416
|
+
};
|
|
417
|
+
const scheduleWorklet = options.scheduleMainThreadWorklet;
|
|
418
|
+
function scheduleTransferWorklet(call) {
|
|
419
|
+
if (active && active.version !== activeVersion)
|
|
420
|
+
return true;
|
|
421
|
+
const instance = active ?? (isRendering.value ? rendering : undefined);
|
|
422
|
+
if (!instance || (instance.phase !== 'waiting' && instance.phase !== 'disposed')) {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
instance.firstFrameWorklets?.push(call);
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
options.scheduleMainThreadWorklet = scheduleTransferWorklet;
|
|
429
|
+
removers.push(() => {
|
|
430
|
+
Object.assign(options, {
|
|
431
|
+
[RENDER_COMPONENT]: renderComponent,
|
|
432
|
+
[COMMIT]: commit,
|
|
433
|
+
[DIFFED]: diffed,
|
|
434
|
+
scheduleMainThreadWorklet: scheduleWorklet,
|
|
435
|
+
});
|
|
436
|
+
});
|
|
302
437
|
// Events of hydrated instances dispatch directly; earlier events have no handler and are dropped.
|
|
303
438
|
enablePublishEvent();
|
|
304
439
|
const core = lynx.getCoreContext();
|
|
440
|
+
removers.push(addReloadScopedEventListener(core, WorkletEvents.FunctionCallRet, data => {
|
|
441
|
+
const call = workletReturns.get(data.resolveId);
|
|
442
|
+
if (!call)
|
|
443
|
+
return;
|
|
444
|
+
workletReturns.delete(data.resolveId);
|
|
445
|
+
call.resolve(data.returnValue);
|
|
446
|
+
}));
|
|
305
447
|
listen(core, '__CreateTransfer', create);
|
|
306
448
|
listen(core, '__TransferFirstFrame', acceptFrame);
|
|
307
|
-
listen(core, '
|
|
449
|
+
listen(core, '__UpdateTransfer', updateProps);
|
|
450
|
+
listen(core, '__ReloadTransfer', reloadProps);
|
|
308
451
|
listen(core, '__DestroyTransfer', scope => dispose(scope, false));
|
|
309
452
|
listen(core, '__TransferCommitResult', result => {
|
|
310
453
|
const instance = instances.get(result.transferId);
|