@lynx-js/react 0.116.4 → 0.117.0
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 +50 -0
- package/package.json +3 -3
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/lazy/compat.js +4 -0
- package/runtime/lazy/react.js +4 -0
- package/runtime/lib/alog/elementPAPICall.js +1 -1
- package/runtime/lib/alog/elementPAPICall.js.map +1 -1
- package/runtime/lib/backgroundSnapshot.d.ts +0 -1
- package/runtime/lib/backgroundSnapshot.js +200 -109
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/debug/profile.d.ts +4 -1
- package/runtime/lib/debug/profile.js +21 -191
- package/runtime/lib/debug/profile.js.map +1 -1
- package/runtime/lib/debug/profileHooks.d.ts +1 -0
- package/runtime/lib/debug/profileHooks.js +200 -0
- package/runtime/lib/debug/profileHooks.js.map +1 -0
- package/runtime/lib/debug/vnodeSource.d.ts +4 -0
- package/runtime/lib/debug/vnodeSource.js +61 -0
- package/runtime/lib/debug/vnodeSource.js.map +1 -0
- package/runtime/lib/hooks/react.d.ts +11 -10
- package/runtime/lib/hooks/react.js +101 -14
- package/runtime/lib/hooks/react.js.map +1 -1
- package/runtime/lib/hydrate.js +1 -1
- package/runtime/lib/hydrate.js.map +1 -1
- package/runtime/lib/lifecycle/destroy.js +1 -1
- package/runtime/lib/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/lifecycle/event/jsReady.js +1 -1
- package/runtime/lib/lifecycle/event/jsReady.js.map +1 -1
- package/runtime/lib/lifecycle/patch/commit.js +1 -1
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/lifecycle/reload.js +1 -1
- package/runtime/lib/lifecycle/reload.js.map +1 -1
- package/runtime/lib/lifecycle/render.js +1 -1
- package/runtime/lib/lifecycle/render.js.map +1 -1
- package/runtime/lib/listUpdateInfo.js +1 -1
- package/runtime/lib/listUpdateInfo.js.map +1 -1
- package/runtime/lib/lynx/env.js +1 -1
- package/runtime/lib/lynx/env.js.map +1 -1
- package/runtime/lib/lynx/tt.js +26 -13
- package/runtime/lib/lynx/tt.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +75 -0
- package/runtime/lib/lynx-api.js +114 -1
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +7 -2
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/snapshot.js +11 -1
- package/runtime/lib/snapshot.js.map +1 -1
- package/testing-library/dist/env/vitest.js +39 -0
- package/testing-library/dist/index.d.ts +8 -0
- package/testing-library/dist/pure.js +1 -2
- package/testing-library/dist/rslib-runtime.js +0 -10
- package/transform/dist/wasm.cjs +1 -1
- package/worklet-runtime/dist/main.js +1 -1
- package/worklet-runtime/lib/bindings/observers.js +3 -1
- package/worklet-runtime/lib/bindings/observers.js.map +1 -1
- package/runtime/lib/debug/utils.d.ts +0 -2
- package/runtime/lib/debug/utils.js +0 -20
- package/runtime/lib/debug/utils.js.map +0 -1
|
@@ -1,199 +1,29 @@
|
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
export function initProfileHook() {
|
|
45
|
-
// early-exit if required profiling APIs are unavailable
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
|
|
5
|
+
export const isProfiling = /* @__PURE__ */ Boolean(lynx.performance?.isProfileRecording?.());
|
|
6
|
+
const noop = () => { };
|
|
7
|
+
const noopFlowId = () => 0;
|
|
8
|
+
export const profileStart = /* @__PURE__ */ ((() => {
|
|
46
9
|
let p;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|| typeof p.profileStart !== 'function'
|
|
50
|
-
|| typeof p.profileEnd !== 'function'
|
|
51
|
-
|| typeof p.profileMark !== 'function'
|
|
52
|
-
|| typeof p.profileFlowId !== 'function') {
|
|
53
|
-
return;
|
|
10
|
+
if (!(p = lynx.performance) || typeof p.profileStart !== 'function') {
|
|
11
|
+
return noop;
|
|
54
12
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// attach a flowId to the component instance.
|
|
62
|
-
// This allows us to trace the flow of its diffing, committing and patching.
|
|
63
|
-
{
|
|
64
|
-
const sFlowID = Symbol('FLOW_ID');
|
|
65
|
-
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
66
|
-
hook(Component.prototype, 'setState', function (old, state, callback) {
|
|
67
|
-
old?.call(this, state, callback);
|
|
68
|
-
if (this[DIRTY]) {
|
|
69
|
-
const type = this[VNODE].type;
|
|
70
|
-
const isClassComponent = typeof type === 'function' && ('prototype' in type)
|
|
71
|
-
&& ('render' in type.prototype);
|
|
72
|
-
if (isClassComponent) {
|
|
73
|
-
profileMark('ReactLynx::setState', {
|
|
74
|
-
flowId: this[sFlowID] ??= profileFlowId(),
|
|
75
|
-
args: buildSetStateProfileMarkArgs(type, this.state, this[NEXT_STATE]),
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
hook(options, DIFF2, (old, vnode, oldVNode) => {
|
|
82
|
-
// We only add profiling trace for Component
|
|
83
|
-
if (typeof vnode.type === 'function') {
|
|
84
|
-
const profileOptions = {};
|
|
85
|
-
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
86
|
-
const c = oldVNode[COMPONENT];
|
|
87
|
-
if (c) {
|
|
88
|
-
const flowId = c[sFlowID];
|
|
89
|
-
delete c[sFlowID];
|
|
90
|
-
if (flowId) {
|
|
91
|
-
globalPatchOptions.flowIds ??= [];
|
|
92
|
-
globalPatchOptions.flowIds.push(flowId);
|
|
93
|
-
profileOptions.flowId = flowId;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
profileStart(`ReactLynx::diff::${ /* #__INLINE__ */getDisplayName(vnode.type)}`, profileOptions);
|
|
98
|
-
}
|
|
99
|
-
old?.(vnode, oldVNode);
|
|
100
|
-
});
|
|
101
|
-
hook(options, DIFFED, (old, vnode) => {
|
|
102
|
-
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
103
|
-
const hooks = vnode[COMPONENT]?.[HOOKS];
|
|
104
|
-
const hookList = hooks?.[LIST];
|
|
105
|
-
if (Array.isArray(hookList)) {
|
|
106
|
-
hookList.forEach((hookState, hookIdx) => {
|
|
107
|
-
hookState['internalNextValue'] = hookState[NEXT_VALUE];
|
|
108
|
-
// define a setter for __N to track the next value of the hook
|
|
109
|
-
Object.defineProperty(hookState, NEXT_VALUE, {
|
|
110
|
-
get: () => hookState['internalNextValue'],
|
|
111
|
-
set: (value) => {
|
|
112
|
-
if (Array.isArray(value)) {
|
|
113
|
-
// hookState[VALUE] is [state, dispatch]
|
|
114
|
-
const currentValueTuple = hookState[VALUE];
|
|
115
|
-
const currentValue = currentValueTuple[0];
|
|
116
|
-
const [nextValue] = value;
|
|
117
|
-
const component = hookState[COMPONENT];
|
|
118
|
-
if (!component) {
|
|
119
|
-
hookState['internalNextValue'] = value;
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const type = component[VNODE].type;
|
|
123
|
-
const flowId = component[sFlowID] ??= profileFlowId();
|
|
124
|
-
profileMark('ReactLynx::hooks::setState', {
|
|
125
|
-
flowId,
|
|
126
|
-
args: {
|
|
127
|
-
hookIdx: String(hookIdx),
|
|
128
|
-
...buildSetStateProfileMarkArgs(type, currentValue, nextValue),
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
hookState['internalNextValue'] = value;
|
|
133
|
-
},
|
|
134
|
-
configurable: true,
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (typeof vnode.type === 'function') {
|
|
140
|
-
profileEnd(); // for options[DIFF]
|
|
141
|
-
}
|
|
142
|
-
old?.(vnode);
|
|
143
|
-
});
|
|
144
|
-
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
145
|
-
hook(options, COMMIT, (old, vnode, commitQueue) => {
|
|
146
|
-
profileStart('ReactLynx::commit', {
|
|
147
|
-
...globalPatchOptions.flowIds
|
|
148
|
-
? {
|
|
149
|
-
flowId: globalPatchOptions.flowIds[0],
|
|
150
|
-
flowIds: globalPatchOptions.flowIds,
|
|
151
|
-
}
|
|
152
|
-
: {},
|
|
153
|
-
});
|
|
154
|
-
old?.(vnode, commitQueue);
|
|
155
|
-
profileEnd();
|
|
156
|
-
});
|
|
157
|
-
}
|
|
13
|
+
return p.profileStart.bind(p);
|
|
14
|
+
})());
|
|
15
|
+
export const profileEnd = /* @__PURE__ */ ((() => {
|
|
16
|
+
let p;
|
|
17
|
+
if (!(p = lynx.performance) || typeof p.profileEnd !== 'function') {
|
|
18
|
+
return noop;
|
|
158
19
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
try {
|
|
166
|
-
return originalRender.call(this, props, state, context);
|
|
167
|
-
}
|
|
168
|
-
finally {
|
|
169
|
-
profileEnd();
|
|
170
|
-
vnode[COMPONENT].render = originalRender;
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
old?.(vnode);
|
|
174
|
-
});
|
|
175
|
-
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
176
|
-
const sPatchLength = Symbol('PATCH_LENGTH');
|
|
177
|
-
hook(options, DIFF, (old, vnode) => {
|
|
178
|
-
if (typeof vnode.type === 'function' && __globalSnapshotPatch) {
|
|
179
|
-
vnode[sPatchLength] = __globalSnapshotPatch.length;
|
|
180
|
-
}
|
|
181
|
-
old?.(vnode);
|
|
182
|
-
});
|
|
183
|
-
hook(options, DIFFED, (old, vnode) => {
|
|
184
|
-
if (typeof vnode.type === 'function' && __globalSnapshotPatch) {
|
|
185
|
-
if (vnode[sPatchLength] === __globalSnapshotPatch.length) {
|
|
186
|
-
// "NoPatch" is a conventional name in Lynx
|
|
187
|
-
profileMark('ReactLynx::diffFinishNoPatch', {
|
|
188
|
-
args: {
|
|
189
|
-
componentName: /* #__INLINE__ */ getDisplayName(vnode.type),
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
delete vnode[sPatchLength];
|
|
194
|
-
}
|
|
195
|
-
old?.(vnode);
|
|
196
|
-
});
|
|
20
|
+
return p.profileEnd.bind(p);
|
|
21
|
+
})());
|
|
22
|
+
export const profileFlowId = /* @__PURE__ */ ((() => {
|
|
23
|
+
let p;
|
|
24
|
+
if (!(p = lynx.performance) || typeof p.profileFlowId !== 'function') {
|
|
25
|
+
return noopFlowId;
|
|
197
26
|
}
|
|
198
|
-
|
|
27
|
+
return p.profileFlowId.bind(p);
|
|
28
|
+
})());
|
|
199
29
|
//# sourceMappingURL=profile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/debug/profile.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/debug/profile.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,qEAAqE;AAErE,MAAM,CAAC,MAAM,WAAW,GAAY,eAAe,CAAC,OAAO,CACzD,IAAI,CAAC,WAAW,EAAE,kBAAkB,EAAE,EAAE,CACzC,CAAC;AAEF,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AACtB,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;AAE3B,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,EAAE;IACjD,IAAI,CAAC,CAAC;IACN,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC,CAAC,EAAE,CAAyC,CAAC;AAE9C,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,EAAE;IAC/C,IAAI,CAAC,CAAC;IACN,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAClE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC,CAAC,EAAE,CAAuC,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,EAAE;IAClD,IAAI,CAAC,CAAC;IACN,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;QACrE,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC,CAAC,EAAE,CAA0C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initProfileHook(): void;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { Component, options } from 'preact';
|
|
5
|
+
import { globalPatchOptions } from '../lifecycle/patch/commit.js';
|
|
6
|
+
import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
|
|
7
|
+
import { COMMIT, COMPONENT, DIFF, DIFF2, DIFFED, DIRTY, HOOKS, LIST, NEXT_STATE, NEXT_VALUE, RENDER, VALUE, VNODE, } from '../renderToOpcodes/constants.js';
|
|
8
|
+
import { getDisplayName, hook } from '../utils.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
|
+
export function initProfileHook() {
|
|
45
|
+
// early-exit if required profiling APIs are unavailable
|
|
46
|
+
let p;
|
|
47
|
+
/* v8 ignore start */
|
|
48
|
+
if (!(p = lynx.performance)
|
|
49
|
+
|| typeof p.profileStart !== 'function'
|
|
50
|
+
|| typeof p.profileEnd !== 'function'
|
|
51
|
+
|| typeof p.profileMark !== 'function'
|
|
52
|
+
|| typeof p.profileFlowId !== 'function') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
/* v8 ignore stop */
|
|
56
|
+
const profileStart = p.profileStart.bind(p);
|
|
57
|
+
const profileEnd = p.profileEnd.bind(p);
|
|
58
|
+
const profileMark = p.profileMark.bind(p);
|
|
59
|
+
const profileFlowId = p.profileFlowId.bind(p);
|
|
60
|
+
// for each setState call, we will add a profiling trace and
|
|
61
|
+
// attach a flowId to the component instance.
|
|
62
|
+
// This allows us to trace the flow of its diffing, committing and patching.
|
|
63
|
+
{
|
|
64
|
+
const sFlowID = Symbol('FLOW_ID');
|
|
65
|
+
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
66
|
+
hook(Component.prototype, 'setState', function (old, state, callback) {
|
|
67
|
+
old?.call(this, state, callback);
|
|
68
|
+
if (this[DIRTY]) {
|
|
69
|
+
const type = this[VNODE].type;
|
|
70
|
+
const isClassComponent = typeof type === 'function' && ('prototype' in type)
|
|
71
|
+
&& ('render' in type.prototype);
|
|
72
|
+
if (isClassComponent) {
|
|
73
|
+
profileMark('ReactLynx::setState', {
|
|
74
|
+
flowId: this[sFlowID] ??= profileFlowId(),
|
|
75
|
+
args: buildSetStateProfileMarkArgs(type, this.state, this[NEXT_STATE]),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
hook(options, DIFF2, (old, vnode, oldVNode) => {
|
|
82
|
+
// We only add profiling trace for Component
|
|
83
|
+
if (typeof vnode.type === 'function') {
|
|
84
|
+
const profileOptions = {};
|
|
85
|
+
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
86
|
+
const c = oldVNode[COMPONENT];
|
|
87
|
+
if (c) {
|
|
88
|
+
const flowId = c[sFlowID];
|
|
89
|
+
delete c[sFlowID];
|
|
90
|
+
if (flowId) {
|
|
91
|
+
globalPatchOptions.flowIds ??= [];
|
|
92
|
+
globalPatchOptions.flowIds.push(flowId);
|
|
93
|
+
profileOptions.flowId = flowId;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
profileStart(`ReactLynx::diff::${ /* #__INLINE__ */getDisplayName(vnode.type)}`, profileOptions);
|
|
98
|
+
}
|
|
99
|
+
old?.(vnode, oldVNode);
|
|
100
|
+
});
|
|
101
|
+
hook(options, DIFFED, (old, vnode) => {
|
|
102
|
+
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
103
|
+
const hooks = vnode[COMPONENT]?.[HOOKS];
|
|
104
|
+
const hookList = hooks?.[LIST];
|
|
105
|
+
if (Array.isArray(hookList)) {
|
|
106
|
+
hookList.forEach((hookState, hookIdx) => {
|
|
107
|
+
hookState['internalNextValue'] = hookState[NEXT_VALUE];
|
|
108
|
+
// define a setter for __N to track the next value of the hook
|
|
109
|
+
Object.defineProperty(hookState, NEXT_VALUE, {
|
|
110
|
+
get: () => hookState['internalNextValue'],
|
|
111
|
+
set: (value) => {
|
|
112
|
+
if (Array.isArray(value)) {
|
|
113
|
+
// hookState[VALUE] is [state, dispatch]
|
|
114
|
+
const currentValueTuple = hookState[VALUE];
|
|
115
|
+
const currentValue = currentValueTuple[0];
|
|
116
|
+
const [nextValue] = value;
|
|
117
|
+
const component = hookState[COMPONENT];
|
|
118
|
+
if (!component) {
|
|
119
|
+
hookState['internalNextValue'] = value;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const type = component[VNODE].type;
|
|
123
|
+
const flowId = component[sFlowID] ??= profileFlowId();
|
|
124
|
+
profileMark('ReactLynx::hooks::setState', {
|
|
125
|
+
flowId,
|
|
126
|
+
args: {
|
|
127
|
+
hookIdx: String(hookIdx),
|
|
128
|
+
...buildSetStateProfileMarkArgs(type, currentValue, nextValue),
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
hookState['internalNextValue'] = value;
|
|
133
|
+
},
|
|
134
|
+
configurable: true,
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (typeof vnode.type === 'function') {
|
|
140
|
+
profileEnd(); // for options[DIFF2]
|
|
141
|
+
}
|
|
142
|
+
old?.(vnode);
|
|
143
|
+
});
|
|
144
|
+
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
145
|
+
hook(options, COMMIT, (old, vnode, commitQueue) => {
|
|
146
|
+
profileStart('ReactLynx::commit', {
|
|
147
|
+
...globalPatchOptions.flowIds
|
|
148
|
+
? {
|
|
149
|
+
flowId: globalPatchOptions.flowIds[0],
|
|
150
|
+
flowIds: globalPatchOptions.flowIds,
|
|
151
|
+
}
|
|
152
|
+
: {},
|
|
153
|
+
});
|
|
154
|
+
old?.(vnode, commitQueue);
|
|
155
|
+
profileEnd();
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Profile the user-provided `render`.
|
|
160
|
+
hook(options, RENDER, (old, vnode) => {
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
162
|
+
const originalRender = vnode[COMPONENT].render;
|
|
163
|
+
vnode[COMPONENT].render = function render(props, state, context) {
|
|
164
|
+
profileStart(`ReactLynx::render::${ /* #__INLINE__ */getDisplayName(vnode.type)}`);
|
|
165
|
+
try {
|
|
166
|
+
return originalRender.call(this, props, state, context);
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
profileEnd();
|
|
170
|
+
vnode[COMPONENT].render = originalRender;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
old?.(vnode);
|
|
174
|
+
});
|
|
175
|
+
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
176
|
+
const sPatchLength = Symbol('PATCH_LENGTH');
|
|
177
|
+
hook(options, DIFF, (old, vnode) => {
|
|
178
|
+
if (typeof vnode.type === 'function' && __globalSnapshotPatch) {
|
|
179
|
+
vnode[sPatchLength] = __globalSnapshotPatch.length;
|
|
180
|
+
}
|
|
181
|
+
old?.(vnode);
|
|
182
|
+
});
|
|
183
|
+
hook(options, DIFFED, (old, vnode) => {
|
|
184
|
+
if (typeof vnode.type === 'function') {
|
|
185
|
+
const patchLength = vnode[sPatchLength];
|
|
186
|
+
delete vnode[sPatchLength];
|
|
187
|
+
if (__globalSnapshotPatch && patchLength === __globalSnapshotPatch.length) {
|
|
188
|
+
// "NoPatch" is a conventional name in Lynx
|
|
189
|
+
profileMark('ReactLynx::diffFinishNoPatch', {
|
|
190
|
+
args: {
|
|
191
|
+
componentName: /* #__INLINE__ */ getDisplayName(vnode.type),
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
old?.(vnode);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=profileHooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileHooks.js","sourceRoot":"","sources":["../../src/debug/profileHooks.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAK5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EACL,MAAM,EACN,SAAS,EACT,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,KAAK,EACL,KAAK,GACN,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnD,M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B,EAAE,EAAE;YACjD,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,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function setupVNodeSourceHook(): void;
|
|
2
|
+
export declare function moveSnapshotVNodeSource(oldId: number, newId: number): void;
|
|
3
|
+
export declare function getSnapshotVNodeSource(id: number): string | undefined;
|
|
4
|
+
export declare function clearSnapshotVNodeSource(): void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { options } from 'preact';
|
|
5
|
+
import { DIFFED, DOM } from '../renderToOpcodes/constants.js';
|
|
6
|
+
const snapshotVNodeSourceMap = new Map();
|
|
7
|
+
let hookInstalled = false;
|
|
8
|
+
function formatSource(source) {
|
|
9
|
+
if (!source.fileName) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
if (typeof source.lineNumber === 'number' && typeof source.columnNumber === 'number') {
|
|
13
|
+
return `${source.fileName}:${source.lineNumber}:${source.columnNumber}`;
|
|
14
|
+
}
|
|
15
|
+
if (typeof source.lineNumber === 'number') {
|
|
16
|
+
return `${source.fileName}:${source.lineNumber}`;
|
|
17
|
+
}
|
|
18
|
+
return source.fileName;
|
|
19
|
+
}
|
|
20
|
+
function captureVNodeSource(vnode) {
|
|
21
|
+
if (typeof vnode.type !== 'string') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const source = vnode.__source;
|
|
25
|
+
const id = vnode[DOM]?.__id;
|
|
26
|
+
if (!source || typeof id !== 'number') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const formattedSource = formatSource(source);
|
|
30
|
+
if (formattedSource) {
|
|
31
|
+
snapshotVNodeSourceMap.set(id, formattedSource);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function setupVNodeSourceHook() {
|
|
35
|
+
if (hookInstalled) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
hookInstalled = true;
|
|
39
|
+
const oldDiffed = options[DIFFED];
|
|
40
|
+
options[DIFFED] = (vnode) => {
|
|
41
|
+
captureVNodeSource(vnode);
|
|
42
|
+
oldDiffed?.(vnode);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function moveSnapshotVNodeSource(oldId, newId) {
|
|
46
|
+
if (oldId === newId) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const source = snapshotVNodeSourceMap.get(oldId);
|
|
50
|
+
if (source) {
|
|
51
|
+
snapshotVNodeSourceMap.set(newId, source);
|
|
52
|
+
snapshotVNodeSourceMap.delete(oldId);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function getSnapshotVNodeSource(id) {
|
|
56
|
+
return snapshotVNodeSourceMap.get(id);
|
|
57
|
+
}
|
|
58
|
+
export function clearSnapshotVNodeSource() {
|
|
59
|
+
snapshotVNodeSourceMap.clear();
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=vnodeSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vnodeSource.js","s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;QACpB,sBAAsB,CAAC,GAAG,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO;IACT,CAAC;IACD,aAAa,GAAG,IAAI,CAAC;IACrB,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE;QAC1B,kBAAkB,CAAC,KAAqB,CAAC,CAAC;QAC1C,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAa,EAAE,KAAa;IAClE,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IACD,MAAM,MAAM,GAAG,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,MAAM,EAAE,CAAC;QACX,sBAAsB,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1C,sBAAsB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,EAAU;IAC/C,OAAO,sBAAsB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,sBAAsB,CAAC,KAAK,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { useCallback, useContext, useDebugValue, useErrorBoundary, useId, useImperativeHandle, useMemo, useReducer, useRef
|
|
1
|
+
import { useCallback, useContext, useDebugValue, useErrorBoundary, useId, useImperativeHandle, useMemo, useState as usePreactState, useReducer, useRef } from 'preact/hooks';
|
|
2
2
|
import type { DependencyList, EffectCallback } from 'react';
|
|
3
|
+
declare const useState: typeof usePreactState;
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Accepts a function that contains imperative, possibly effectful code. The effects run after main thread dom update without blocking it.
|
|
5
|
+
* Accepts a function that contains imperative, possibly effectful code.
|
|
6
|
+
* The effects run after main thread dom update without blocking it.
|
|
7
7
|
*
|
|
8
8
|
* @param effect - Imperative function that can return a cleanup function
|
|
9
9
|
* @param deps - If present, effect will only activate if the values in the list change (using ===).
|
|
10
10
|
*
|
|
11
11
|
* @public
|
|
12
|
-
*
|
|
13
|
-
* @deprecated `useLayoutEffect` in the background thread cannot offer the precise timing for reading layout information and synchronously re-render, which is different from React.
|
|
14
12
|
*/
|
|
15
|
-
declare
|
|
13
|
+
declare const useEffect: (effect: EffectCallback, deps?: DependencyList) => void;
|
|
16
14
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* `useLayoutEffect` is now an alias of `useEffect`. Use `useEffect` instead.
|
|
16
|
+
*
|
|
17
|
+
* Accepts a function that contains imperative, possibly effectful code. The effects run after main thread dom update without blocking it.
|
|
19
18
|
*
|
|
20
19
|
* @param effect - Imperative function that can return a cleanup function
|
|
21
20
|
* @param deps - If present, effect will only activate if the values in the list change (using ===).
|
|
22
21
|
*
|
|
23
22
|
* @public
|
|
23
|
+
*
|
|
24
|
+
* @deprecated `useLayoutEffect` in the background thread cannot offer the precise timing for reading layout information and synchronously re-render, which is different from React.
|
|
24
25
|
*/
|
|
25
|
-
declare
|
|
26
|
+
declare const useLayoutEffect: (effect: EffectCallback, deps?: DependencyList) => void;
|
|
26
27
|
export { useState, useReducer, useRef, useImperativeHandle, useLayoutEffect, useEffect, useCallback, useMemo, useContext, useDebugValue, useErrorBoundary, useId, };
|