@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
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { setupLynxEnv } from '../../../src/element-template/lynx/env.js';
|
|
4
|
-
import { ElementTemplateEnvManager } from '../test-utils/debug/envManager.js';
|
|
5
|
-
|
|
6
|
-
const envManager = new ElementTemplateEnvManager();
|
|
7
|
-
|
|
8
|
-
type GlobalWithEnv = typeof globalThis & {
|
|
9
|
-
__OnLifecycleEvent?: ReturnType<typeof vi.fn>;
|
|
10
|
-
NativeModules?: unknown;
|
|
11
|
-
SystemInfo?: unknown;
|
|
12
|
-
processData?: (data: unknown, processorName?: string) => unknown;
|
|
13
|
-
__I18N_RESOURCE_TRANSLATION__?: unknown;
|
|
14
|
-
__EXTRACT_STR__?: boolean;
|
|
15
|
-
__EXTRACT_STR_IDENT_FLAG__?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type LynxWithSystemInfo = typeof globalThis.lynx & {
|
|
19
|
-
SystemInfo?: unknown;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
describe('setupLynxEnv', () => {
|
|
23
|
-
const g = globalThis as GlobalWithEnv;
|
|
24
|
-
let originalOnLifecycleEvent: typeof g.__OnLifecycleEvent;
|
|
25
|
-
let originalProcessData: typeof g.processData;
|
|
26
|
-
let originalNativeModules: typeof g.NativeModules;
|
|
27
|
-
let originalSystemInfo: typeof g.SystemInfo;
|
|
28
|
-
let originalLynxSystemInfo: LynxWithSystemInfo['SystemInfo'];
|
|
29
|
-
let originalI18n: typeof g.__I18N_RESOURCE_TRANSLATION__;
|
|
30
|
-
let originalExtractStr: typeof g.__EXTRACT_STR__;
|
|
31
|
-
let originalExtractStrFlag: typeof g.__EXTRACT_STR_IDENT_FLAG__;
|
|
32
|
-
let originalReportError: typeof globalThis.lynx.reportError;
|
|
33
|
-
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
vi.clearAllMocks();
|
|
36
|
-
originalOnLifecycleEvent = g.__OnLifecycleEvent;
|
|
37
|
-
originalProcessData = g.processData;
|
|
38
|
-
originalNativeModules = g.NativeModules;
|
|
39
|
-
originalSystemInfo = g.SystemInfo;
|
|
40
|
-
originalLynxSystemInfo = (globalThis.lynx as LynxWithSystemInfo).SystemInfo;
|
|
41
|
-
originalI18n = g.__I18N_RESOURCE_TRANSLATION__;
|
|
42
|
-
originalExtractStr = g.__EXTRACT_STR__;
|
|
43
|
-
originalExtractStrFlag = g.__EXTRACT_STR_IDENT_FLAG__;
|
|
44
|
-
originalReportError = globalThis.lynx.reportError;
|
|
45
|
-
g.__EXTRACT_STR__ = false;
|
|
46
|
-
g.__EXTRACT_STR_IDENT_FLAG__ = undefined;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
g.__OnLifecycleEvent = originalOnLifecycleEvent;
|
|
51
|
-
|
|
52
|
-
if (originalProcessData === undefined) {
|
|
53
|
-
delete g.processData;
|
|
54
|
-
} else {
|
|
55
|
-
g.processData = originalProcessData;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (originalNativeModules === undefined) {
|
|
59
|
-
delete g.NativeModules;
|
|
60
|
-
} else {
|
|
61
|
-
g.NativeModules = originalNativeModules;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (originalSystemInfo === undefined) {
|
|
65
|
-
delete g.SystemInfo;
|
|
66
|
-
} else {
|
|
67
|
-
g.SystemInfo = originalSystemInfo;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (originalLynxSystemInfo === undefined) {
|
|
71
|
-
delete (globalThis.lynx as LynxWithSystemInfo).SystemInfo;
|
|
72
|
-
} else {
|
|
73
|
-
(globalThis.lynx as LynxWithSystemInfo).SystemInfo = originalLynxSystemInfo;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (originalI18n === undefined) {
|
|
77
|
-
delete g.__I18N_RESOURCE_TRANSLATION__;
|
|
78
|
-
} else {
|
|
79
|
-
g.__I18N_RESOURCE_TRANSLATION__ = originalI18n;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (originalExtractStr === undefined) {
|
|
83
|
-
delete g.__EXTRACT_STR__;
|
|
84
|
-
} else {
|
|
85
|
-
g.__EXTRACT_STR__ = originalExtractStr;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (originalExtractStrFlag === undefined) {
|
|
89
|
-
delete g.__EXTRACT_STR_IDENT_FLAG__;
|
|
90
|
-
} else {
|
|
91
|
-
g.__EXTRACT_STR_IDENT_FLAG__ = originalExtractStrFlag;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
globalThis.lynx.reportError = originalReportError;
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('merges initData and updateData in JS env', () => {
|
|
98
|
-
envManager.resetEnv('background');
|
|
99
|
-
globalThis.lynx.getApp()._params = {
|
|
100
|
-
initData: { answer: 41, stale: true },
|
|
101
|
-
updateData: { answer: 42, fresh: true },
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
setupLynxEnv();
|
|
105
|
-
|
|
106
|
-
expect(globalThis.lynx.__initData).toEqual({
|
|
107
|
-
answer: 42,
|
|
108
|
-
stale: true,
|
|
109
|
-
fresh: true,
|
|
110
|
-
});
|
|
111
|
-
expect(typeof globalThis.lynx.registerDataProcessors).toBe('function');
|
|
112
|
-
expect(() => globalThis.lynx.registerDataProcessors()).not.toThrow();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('falls back to empty initData when reading params throws', () => {
|
|
116
|
-
envManager.resetEnv('background');
|
|
117
|
-
Object.defineProperty(globalThis.lynx.getApp(), '_params', {
|
|
118
|
-
configurable: true,
|
|
119
|
-
get() {
|
|
120
|
-
throw new Error('boom');
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
setupLynxEnv();
|
|
125
|
-
|
|
126
|
-
expect(globalThis.lynx.__initData).toEqual({});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('treats missing initData and updateData params as empty objects in JS env', () => {
|
|
130
|
-
envManager.resetEnv('background');
|
|
131
|
-
Object.defineProperty(globalThis.lynx.getApp(), '_params', {
|
|
132
|
-
configurable: true,
|
|
133
|
-
value: {
|
|
134
|
-
initData: undefined,
|
|
135
|
-
updateData: undefined,
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
setupLynxEnv();
|
|
140
|
-
|
|
141
|
-
expect(globalThis.lynx.__initData).toEqual({});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('installs lepus event bridge and processData handlers', () => {
|
|
145
|
-
envManager.resetEnv('main');
|
|
146
|
-
g.__OnLifecycleEvent = vi.fn();
|
|
147
|
-
|
|
148
|
-
setupLynxEnv();
|
|
149
|
-
|
|
150
|
-
globalThis.lynx.triggerGlobalEventFromLepus?.('ready', { ok: true });
|
|
151
|
-
expect(g.__OnLifecycleEvent).toHaveBeenCalledWith([
|
|
152
|
-
'globalEventFromLepus',
|
|
153
|
-
['ready', { ok: true }],
|
|
154
|
-
]);
|
|
155
|
-
expect('NativeModules' in g).toBe(true);
|
|
156
|
-
expect(g.NativeModules).toBeUndefined();
|
|
157
|
-
|
|
158
|
-
const defaultDataProcessor = vi.fn((data: { value: number }) => ({ doubled: data.value * 2 }));
|
|
159
|
-
const namedDataProcessor = vi.fn((data: { value: number }) => ({ named: data.value }));
|
|
160
|
-
globalThis.lynx.registerDataProcessors?.({
|
|
161
|
-
defaultDataProcessor,
|
|
162
|
-
dataProcessors: {
|
|
163
|
-
named: namedDataProcessor,
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
expect(g.processData?.({ value: 2 }, 'named')).toEqual({ named: 2 });
|
|
168
|
-
expect(g.processData?.({ value: 3 })).toEqual({ doubled: 6 });
|
|
169
|
-
expect(namedDataProcessor).toHaveBeenCalledTimes(1);
|
|
170
|
-
expect(defaultDataProcessor).toHaveBeenCalledTimes(1);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('reports data processor errors and returns an empty object', () => {
|
|
174
|
-
envManager.resetEnv('main');
|
|
175
|
-
const reportError = vi.fn();
|
|
176
|
-
globalThis.lynx.reportError = reportError;
|
|
177
|
-
|
|
178
|
-
setupLynxEnv();
|
|
179
|
-
globalThis.lynx.registerDataProcessors?.({
|
|
180
|
-
defaultDataProcessor() {
|
|
181
|
-
throw new Error('processor failed');
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
expect(g.processData?.({ value: 1 })).toEqual({});
|
|
186
|
-
expect(reportError).toHaveBeenCalledTimes(1);
|
|
187
|
-
expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('processor failed');
|
|
188
|
-
reportError.mockClear();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('injects i18n and extract flags only before the default processor executes once', () => {
|
|
192
|
-
envManager.resetEnv('main');
|
|
193
|
-
g.__I18N_RESOURCE_TRANSLATION__ = { hello: 'world' };
|
|
194
|
-
g.__EXTRACT_STR__ = true;
|
|
195
|
-
g.__EXTRACT_STR_IDENT_FLAG__ = '__extract__';
|
|
196
|
-
|
|
197
|
-
setupLynxEnv();
|
|
198
|
-
globalThis.lynx.registerDataProcessors?.({
|
|
199
|
-
defaultDataProcessor: (data: { value: number }) => ({ value: data.value }),
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
expect(g.processData?.({ value: 1 })).toEqual({
|
|
203
|
-
value: 1,
|
|
204
|
-
__I18N_RESOURCE_TRANSLATION__: { hello: 'world' },
|
|
205
|
-
_EXTRACT_STR: '__extract__',
|
|
206
|
-
});
|
|
207
|
-
expect(g.processData?.({ value: 2 })).toEqual({
|
|
208
|
-
value: 2,
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('exposes SystemInfo in main-thread env for worklet runtime initialization', () => {
|
|
213
|
-
envManager.resetEnv('main');
|
|
214
|
-
const systemInfo = { lynxSdkVersion: '4.1' };
|
|
215
|
-
(globalThis.lynx as LynxWithSystemInfo).SystemInfo = systemInfo;
|
|
216
|
-
|
|
217
|
-
setupLynxEnv();
|
|
218
|
-
|
|
219
|
-
expect(g.SystemInfo).toBe(systemInfo);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('falls back to empty SystemInfo when lynx.SystemInfo is unavailable', () => {
|
|
223
|
-
envManager.resetEnv('main');
|
|
224
|
-
delete (globalThis.lynx as LynxWithSystemInfo).SystemInfo;
|
|
225
|
-
|
|
226
|
-
setupLynxEnv();
|
|
227
|
-
|
|
228
|
-
expect(g.SystemInfo).toEqual({});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('falls back to raw data when named or default processors are missing', () => {
|
|
232
|
-
envManager.resetEnv('main');
|
|
233
|
-
|
|
234
|
-
setupLynxEnv();
|
|
235
|
-
globalThis.lynx.registerDataProcessors?.({
|
|
236
|
-
dataProcessors: {},
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
expect(g.processData?.({ value: 1 }, 'missing')).toEqual({ value: 1 });
|
|
240
|
-
expect(g.processData?.({ value: 2 })).toEqual({ value: 2 });
|
|
241
|
-
});
|
|
242
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function setupLynxEnv(): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/element-template/lynx/env.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAGvE,MAAM,UAAU,YAAY;IAC1B,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,IAAI,QAAQ,GAA4B,EAAE,CAAC;QAC3C,IAAI,UAAU,GAA4B,EAAE,CAAC;QAE7C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC;YACrC,IAAI,MAAM,EAAE,CAAC;gBACX,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;gBACjC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;YACvC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QAEV,IAAI,CAAC,UAAU,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,UAAU,EAAE,CAAC;QACjD,IAAI,CAAC,sBAAsB,GAAG,cAAY,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,CAAC,UAAU,GAAG;QAChB,kCAAkC;SACnC,CAAC;QACD,UAA2D,CAAC,UAAU;YACpE,IAA+C,CAAC,UAAU,IAAI,EAAE,CAAC;QAEpE,IAAI,CAAC,2BAA2B,GAAG,UACjC,SAAiB,EACjB,MAAW;YAEX,kBAAkB,CAAC,CAAC,sBAAsB,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;QACpE,CAAC,CAAC;QAEF,CAAC;YACC,+DAA+D;YAC/D,SAAS,MAAM,CAAC,KAAa;gBAC3B,OAAO,SAAS,KAAK,SAAS,CAAC;YACjC,CAAC;YACD,8GAA8G;YAC9G,wBAAwB;YACxB,IAAI,OAAO,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,WAAW,EAAE,CAAC;gBAClD,wBAAwB;gBACxB,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;YACrC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,sBAAsB,GAAG,UAC5B,uBAAiD;YAEjD,UAAU,CAAC,WAAW,GAAG,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;QACtE,CAAC,CAAC;QAEF,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAChC,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 { createProcessData } from '../../core/lynx-data-processors.js';\nimport type { DataProcessorDefinition } from '../../core/lynx-data-processors.js';\n\nexport function setupLynxEnv(): void {\n if (!__LEPUS__) {\n let initData: Record<string, unknown> = {};\n let updateData: Record<string, unknown> = {};\n\n try {\n const params = lynx.getApp()._params;\n if (params) {\n initData = params.initData ?? {};\n updateData = params.updateData ?? {};\n }\n } catch {}\n\n lynx.__initData = { ...initData, ...updateData };\n lynx.registerDataProcessors = function() {};\n }\n\n if (__LEPUS__) {\n lynx.__initData = {\n /* available only in renderPage */\n };\n (globalThis as typeof globalThis & { SystemInfo?: unknown }).SystemInfo =\n (lynx as typeof lynx & { SystemInfo?: unknown }).SystemInfo ?? {};\n\n lynx.triggerGlobalEventFromLepus = function(\n eventName: string,\n params: any,\n ) {\n __OnLifecycleEvent(['globalEventFromLepus', [eventName, params]]);\n };\n\n {\n // eslint-disable-next-line unicorn/consistent-function-scoping\n function __name(empty: string) {\n return `Native${empty}Modules`;\n }\n // TODO(hongzhiyuan.hzy): make sure this is run before any other code (especially code access `NativeModules`)\n // @ts-expect-error hack\n if (typeof globalThis[__name('')] === 'undefined') {\n // @ts-expect-error hack\n globalThis[__name('')] = undefined;\n }\n }\n\n lynx.registerDataProcessors = function(\n dataProcessorDefinition?: DataProcessorDefinition,\n ) {\n globalThis.processData = createProcessData(dataProcessorDefinition);\n };\n\n lynx.registerDataProcessors();\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main-thread-function.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-function.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EACL,qBAAqB,EACrB,8BAA8B,GAC/B,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAE9E,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;IAChD,qCAAqC;QACnC,OAAO,yBAAyB,EAAE,IAAI,CAAC,0BAA0B,EAAE,CAAC;IACtE,CAAC;CACF,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,EAAM;IAEN,OAAO,mBAAmB,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,6CAA6C;IAC3D,8BAA8B,EAAE,CAAC;IACjC,+BAA+B,EAAE,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2026 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 {\n createRunOnMainThread,\n takeDelayedRunOnMainThreadData,\n} from '../../../core/thread-function-call/main-thread.js';\nimport { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';\nimport { isElementTemplateHydrated } from '../../background/commit-hook.js';\nimport { isElementTemplateRendering } from '../../background/render-scope.js';\n\nconst runOnMainThreadImpl = createRunOnMainThread({\n shouldDispatchRunOnMainThreadDirectly() {\n return isElementTemplateHydrated() && !isElementTemplateRendering();\n },\n});\n\n/**\n * `runOnMainThread` allows triggering main-thread functions on the main thread asynchronously.\n * @public\n */\nexport function runOnMainThread<R, Fn extends (...args: any[]) => R>(\n fn: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n return runOnMainThreadImpl(fn);\n}\n\nexport function resetElementTemplateMainThreadFunctionRuntime(): void {\n takeDelayedRunOnMainThreadData();\n resetFunctionCallReturnListener();\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
// for better reuse if runtime is changed
|
|
5
|
-
export function factory({ createElement, useMemo, Suspense, lazy }, loadLazyBundle) {
|
|
6
|
-
/**
|
|
7
|
-
* @internal a polyfill for <component is=? />
|
|
8
|
-
*/
|
|
9
|
-
const __ComponentIsPolyfill = ({ is, ...props }) => {
|
|
10
|
-
if (typeof is !== 'string') {
|
|
11
|
-
lynx.reportError(new Error('You must provide a string to props `is` when using syntax `<component is=? />`.'));
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
const D = useMemo(() => lazy(() => loadLazyBundle(is)), [is]);
|
|
16
|
-
return createElement(Suspense, { key: is }, createElement(D, props));
|
|
17
|
-
};
|
|
18
|
-
return __ComponentIsPolyfill;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=componentIs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"componentIs.js","sourceRoot":"","sources":["../../../src/snapshot/compat/componentIs.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,yCAAyC;AACzC,MAAM,UAAU,OAAO,CACrB,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAA0B,EAClE,cAAmB;IAEnB;;OAEG;IACH,MAAM,qBAAqB,GAAuB,CAAC,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;QACrE,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC3B,IAAI,CAAC,WAAW,CACd,IAAI,KAAK,CACP,iFAAiF,CAClF,CACF,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;QACD,aAAa;QACb,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9D,OAAO,aAAa,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACvE,CAAC,CAAC;IAEF,OAAO,qBAAqB,CAAC;AAC/B,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 type { FC } from 'react';\n\n// for better reuse if runtime is changed\nexport function factory(\n { createElement, useMemo, Suspense, lazy }: typeof import('react'),\n loadLazyBundle: any,\n): FC<{ is: string }> {\n /**\n * @internal a polyfill for <component is=? />\n */\n const __ComponentIsPolyfill: FC<{ is: string }> = ({ is, ...props }) => {\n if (typeof is !== 'string') {\n lynx.reportError(\n new Error(\n 'You must provide a string to props `is` when using syntax `<component is=? />`.',\n ),\n );\n return null;\n }\n // @ts-ignore\n const D = useMemo(() => lazy(() => loadLazyBundle(is)), [is]);\n return createElement(Suspense, { key: is }, createElement(D, props));\n };\n\n return __ComponentIsPolyfill;\n}\n"]}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
|
|
5
|
-
import type { FC } from 'react';
|
|
6
|
-
|
|
7
|
-
// for better reuse if runtime is changed
|
|
8
|
-
export function factory(
|
|
9
|
-
{ createElement, useMemo, Suspense, lazy }: typeof import('react'),
|
|
10
|
-
loadLazyBundle: any,
|
|
11
|
-
): FC<{ is: string }> {
|
|
12
|
-
/**
|
|
13
|
-
* @internal a polyfill for <component is=? />
|
|
14
|
-
*/
|
|
15
|
-
const __ComponentIsPolyfill: FC<{ is: string }> = ({ is, ...props }) => {
|
|
16
|
-
if (typeof is !== 'string') {
|
|
17
|
-
lynx.reportError(
|
|
18
|
-
new Error(
|
|
19
|
-
'You must provide a string to props `is` when using syntax `<component is=? />`.',
|
|
20
|
-
),
|
|
21
|
-
);
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
const D = useMemo(() => lazy(() => loadLazyBundle(is)), [is]);
|
|
26
|
-
return createElement(Suspense, { key: is }, createElement(D, props));
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return __ComponentIsPolyfill;
|
|
30
|
-
}
|
|
File without changes
|
/package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.d.ts
RENAMED
|
File without changes
|