@lynx-js/react-canary 0.121.2 → 0.121.3-canary-20260623-c03d3318
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 +52 -61
- package/package.json +1 -1
- package/runtime/lib/core/background-function/exec-map.d.ts +11 -0
- package/runtime/lib/core/background-function/exec-map.js +39 -0
- package/runtime/lib/core/background-function/exec-map.js.map +1 -0
- package/runtime/lib/core/background-function/handle.d.ts +8 -0
- package/runtime/lib/core/background-function/handle.js +25 -0
- package/runtime/lib/core/background-function/handle.js.map +1 -0
- package/runtime/lib/core/background-function/run-on-background.d.ts +8 -0
- package/runtime/lib/{snapshot/worklet/call/runOnBackground.js → core/background-function/run-on-background.js} +39 -33
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -0
- package/runtime/lib/core/initData.js +17 -0
- package/runtime/lib/core/initData.js.map +1 -1
- package/runtime/lib/core/lynx-page-data.js +6 -0
- package/runtime/lib/core/lynx-page-data.js.map +1 -1
- package/runtime/lib/core/lynx-update-data.js +6 -0
- package/runtime/lib/core/lynx-update-data.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.d.ts +4 -0
- package/runtime/lib/core/runtime-destroy.js +18 -0
- package/runtime/lib/core/runtime-destroy.js.map +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.d.ts +5 -0
- package/runtime/lib/core/thread-function-call/main-thread.js +69 -0
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -0
- package/runtime/lib/core/thread-function-call/return-value.d.ts +2 -0
- package/runtime/lib/core/thread-function-call/return-value.js +67 -0
- package/runtime/lib/core/thread-function-call/return-value.js.map +1 -0
- package/runtime/lib/element-template/background/attr-slots.d.ts +1 -1
- package/runtime/lib/element-template/background/attr-slots.js +8 -7
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +79 -59
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +4 -0
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +23 -4
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +33 -14
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/background/instance.d.ts +1 -1
- package/runtime/lib/element-template/background/instance.js +10 -3
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/background/render-scope.d.ts +4 -0
- package/runtime/lib/element-template/background/render-scope.js +43 -0
- package/runtime/lib/element-template/background/render-scope.js.map +1 -0
- package/runtime/lib/element-template/index.d.ts +2 -0
- package/runtime/lib/element-template/index.js +2 -0
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +4 -1
- package/runtime/lib/element-template/internal.js +5 -5
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js +2 -0
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +2 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +4 -0
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +41 -16
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +4 -0
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/spread.d.ts +1 -4
- package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +5 -2
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/protocol/update-event.d.ts +15 -0
- package/runtime/lib/element-template/protocol/update-event.js +24 -0
- package/runtime/lib/element-template/protocol/update-event.js.map +1 -0
- package/runtime/lib/element-template/runtime/patch.d.ts +1 -1
- package/runtime/lib/element-template/runtime/patch.js +18 -2
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +7 -5
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.js +7 -1
- 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 +10 -0
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +30 -0
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +15 -0
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +91 -0
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.d.ts +15 -0
- package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js +29 -0
- package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-function.d.ts +6 -0
- package/runtime/lib/element-template/runtime/template/main-thread-function.js +24 -0
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -0
- package/runtime/lib/internal.d.ts +1 -1
- package/runtime/lib/internal.js +1 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +1 -1
- package/runtime/lib/lynx-api.js +1 -1
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/{snapshot/worklet/indexMap.d.ts → shared/index-map.d.ts} +2 -2
- package/runtime/lib/{snapshot/worklet/indexMap.js → shared/index-map.js} +5 -3
- package/runtime/lib/shared/index-map.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/patch/commit.js +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/snapshot/lynx/tt.js +1 -1
- package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +10 -31
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ctx.js +2 -2
- package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
- package/runtime/lib/snapshot/worklet/destroy.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/destroy.js +2 -5
- package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/observers.d.ts +7 -0
- package/runtime/lib/worklet-runtime/bindings/observers.js +14 -1
- package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +2 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js +6 -2
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +3 -0
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +17 -2
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/worklet-runtime/dev.js +26 -8
- package/runtime/worklet-runtime/main.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.d.ts +0 -3
- package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.js +0 -10
- package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.js.map +0 -1
- package/runtime/lib/snapshot/worklet/call/execMap.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/call/execMap.js +0 -43
- package/runtime/lib/snapshot/worklet/call/execMap.js.map +0 -1
- package/runtime/lib/snapshot/worklet/call/functionCall.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/call/functionCall.js +0 -33
- package/runtime/lib/snapshot/worklet/call/functionCall.js.map +0 -1
- package/runtime/lib/snapshot/worklet/call/runOnBackground.d.ts +0 -20
- package/runtime/lib/snapshot/worklet/call/runOnBackground.js.map +0 -1
- package/runtime/lib/snapshot/worklet/call/transformToWorklet.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/call/transformToWorklet.js +0 -22
- package/runtime/lib/snapshot/worklet/call/transformToWorklet.js.map +0 -1
- package/runtime/lib/snapshot/worklet/indexMap.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @lynx-js/react
|
|
2
2
|
|
|
3
|
+
## 0.121.3-canary-20260623050612-c03d3318e2de9cb6061563f582f4c606c954bbd2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Report a development error when a page-data reset is combined with `withInitDataInState`. ([#2869](https://github.com/lynx-family/lynx-stack/pull/2869))
|
|
8
|
+
|
|
9
|
+
`withInitDataInState` merges `lynx.__initData` into the wrapped component's state, so resetting the page data — `updatePage(..., { resetPageData: true })` on the main thread, or `updateData(..., { type: 'reset' })` on the background thread — cannot drop the keys the reset removed; the component keeps rendering the stale keys. A dev-only error is now reported (once per reset path) on both threads, pointing to `useInitData()` instead. The check is gated by `__DEV__` and is fully removed from production builds.
|
|
10
|
+
|
|
3
11
|
## 0.121.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -9,13 +17,13 @@
|
|
|
9
17
|
Previously, the compat transform could short-circuit while scanning opening attributes and treat:
|
|
10
18
|
|
|
11
19
|
```jsx
|
|
12
|
-
<Component removeComponentElement={true} {...props}
|
|
20
|
+
<Component removeComponentElement={true} {...props} />
|
|
13
21
|
```
|
|
14
22
|
|
|
15
23
|
differently from:
|
|
16
24
|
|
|
17
25
|
```jsx
|
|
18
|
-
<Component {...props} removeComponentElement={true}
|
|
26
|
+
<Component {...props} removeComponentElement={true} />
|
|
19
27
|
```
|
|
20
28
|
|
|
21
29
|
The transform now collects the full opening-attribute state first, so both prop orders compile the same way in normal and `compilerOnly` modes.
|
|
@@ -41,7 +49,7 @@
|
|
|
41
49
|
- Support `React.createElement(type, props, children)` API. ([#2360](https://github.com/lynx-family/lynx-stack/pull/2360))
|
|
42
50
|
|
|
43
51
|
```jsx
|
|
44
|
-
React.createElement(
|
|
52
|
+
React.createElement("view", { style }, <text>hello</text>);
|
|
45
53
|
// equivalent to
|
|
46
54
|
<view style={style}>
|
|
47
55
|
<text>hello</text>
|
|
@@ -103,7 +111,6 @@
|
|
|
103
111
|
- Fix ref callbacks not being cleaned up or re-applied correctly when the ref at the same element slot changes across rerenders that happen before hydration (e.g. a `useEffect` triggering `setState` during the initial background render). ([#2500](https://github.com/lynx-family/lynx-stack/pull/2500))
|
|
104
112
|
|
|
105
113
|
- fix: reduce redundant updates for main-thread handlers and gestures ([#2188](https://github.com/lynx-family/lynx-stack/pull/2188))
|
|
106
|
-
|
|
107
114
|
- Updates are faster when the main-thread event handler or gesture object is stable across rerenders (fewer unnecessary native updates).
|
|
108
115
|
- Spread props rerenders that don't semantically change the handler/gesture no longer trigger redundant updates.
|
|
109
116
|
- Removing a gesture from spread props reliably clears the gesture state on the target element.
|
|
@@ -123,7 +130,6 @@
|
|
|
123
130
|
- Remove stale gestures when gestures are removed ([#2297](https://github.com/lynx-family/lynx-stack/pull/2297))
|
|
124
131
|
|
|
125
132
|
- Trace refactor ([#2466](https://github.com/lynx-family/lynx-stack/pull/2466))
|
|
126
|
-
|
|
127
133
|
- Remove `ReactLynx::renderOpcodes` from the trace
|
|
128
134
|
- Use `ReactLynx::transferRoot` to measure the time spent transferring the root to the background thread
|
|
129
135
|
|
|
@@ -134,8 +140,8 @@
|
|
|
134
140
|
Create a config file `rstest.config.ts` with the following content:
|
|
135
141
|
|
|
136
142
|
```ts
|
|
137
|
-
import { defineConfig } from
|
|
138
|
-
import { withLynxConfig } from
|
|
143
|
+
import { defineConfig } from "@rstest/core";
|
|
144
|
+
import { withLynxConfig } from "@lynx-js/react/testing-library/rstest-config";
|
|
139
145
|
|
|
140
146
|
export default defineConfig({
|
|
141
147
|
extends: withLynxConfig(),
|
|
@@ -185,7 +191,6 @@
|
|
|
185
191
|
### Minor Changes
|
|
186
192
|
|
|
187
193
|
- feat: export `GlobalPropsProvider`, `GlobalPropsConsumer`, `useGlobalProps` and `useGlobalPropsChanged` for `__globalProps` ([#2346](https://github.com/lynx-family/lynx-stack/pull/2346))
|
|
188
|
-
|
|
189
194
|
- `GlobalPropsProvider`: A Provider component that accepts `children`. It is used to provide the `lynx.__globalProps` context.
|
|
190
195
|
- `GlobalPropsConsumer`: A Consumer component that accepts a function as a child. It is used to consume the `lynx.__globalProps` context.
|
|
191
196
|
- `useGlobalProps`: A hook that returns the `lynx.__globalProps` object. It triggers a re-render when `lynx.__globalProps` changes.
|
|
@@ -200,7 +205,6 @@
|
|
|
200
205
|
Upgrade preact from [f7693b72](https://github.com/preactjs/preact/commit/f7693b72ecb4a40c66e6e47f54e2d4edc374c9f0) to [55254ef7](https://github.com/preactjs/preact/commit/55254ef7021e563cc1a86fb816058964a1b6a29a), see diffs at [f7693b72...55254ef7](https://github.com/preactjs/preact/compare/f7693b72ecb4a40c66e6e47f54e2d4edc374c9f0...preactjs:preact:55254ef7021e563cc1a86fb816058964a1b6a29a?expand=1).
|
|
201
206
|
|
|
202
207
|
- feat: add `globalPropsMode` option to `PluginReactLynxOptions` ([#2346](https://github.com/lynx-family/lynx-stack/pull/2346))
|
|
203
|
-
|
|
204
208
|
- When configured to `"event"`, `updateGlobalProps` will only trigger a global event and skip the `runWithForce` flow.
|
|
205
209
|
- Defaults to `"reactive"`, which means `updateGlobalProps` will trigger re-render automatically.
|
|
206
210
|
|
|
@@ -220,7 +224,6 @@
|
|
|
220
224
|
|
|
221
225
|
- Improve React runtime hook profiling. ([#2235](https://github.com/lynx-family/lynx-stack/pull/2235))
|
|
222
226
|
Enable Profiling recording first, then enter the target page so the trace includes full render/hydrate phases.
|
|
223
|
-
|
|
224
227
|
- Record trace events for `useEffect` / `useLayoutEffect` hook entry, callback, and cleanup phases.
|
|
225
228
|
- Log trace events for `useState` setter calls.
|
|
226
229
|
- Wire `profileFlowId` support in debug profile utilities and attach flow IDs to related hook traces.
|
|
@@ -269,7 +272,6 @@
|
|
|
269
272
|
- Bump `swc_core` v56. ([#2154](https://github.com/lynx-family/lynx-stack/pull/2154))
|
|
270
273
|
|
|
271
274
|
- Use `disableDeprecatedWarning` option to suppress BROKEN warnings during compilation. ([#2157](https://github.com/lynx-family/lynx-stack/pull/2157))
|
|
272
|
-
|
|
273
275
|
1. BROKEN: `getNodeRef`/`getNodeRefFromRoot`/`createSelectorQuery` on component instance is broken and MUST be migrated in ReactLynx 3.0, please use ref or lynx.createSelectorQuery instead.
|
|
274
276
|
2. BROKEN: `getElementById` on component instance is broken and MUST be migrated in ReactLynx 3.0, please use ref or lynx.getElementById instead.
|
|
275
277
|
|
|
@@ -307,9 +309,9 @@
|
|
|
307
309
|
|
|
308
310
|
```typescript
|
|
309
311
|
function getStyle(ele: MainThread.Element) {
|
|
310
|
-
|
|
311
|
-
const width = ele.getComputedStyleProperty(
|
|
312
|
-
const transformMatrix = ele.getComputedStyleProperty(
|
|
312
|
+
"main thread";
|
|
313
|
+
const width = ele.getComputedStyleProperty("width"); // Returns 300px
|
|
314
|
+
const transformMatrix = ele.getComputedStyleProperty("transform"); // Returns matrix(2, 0, 0, 2, 200, 400)
|
|
313
315
|
}
|
|
314
316
|
```
|
|
315
317
|
|
|
@@ -324,7 +326,7 @@
|
|
|
324
326
|
```ts
|
|
325
327
|
const LazyComponent = lazy(async () => {
|
|
326
328
|
try {
|
|
327
|
-
const mod = await import(
|
|
329
|
+
const mod = await import("./lazy-bundle");
|
|
328
330
|
return mod.default;
|
|
329
331
|
} catch (error) {
|
|
330
332
|
console.error(`Lazy Bundle load failed message: ${error.message}`);
|
|
@@ -352,14 +354,13 @@
|
|
|
352
354
|
- Auto define lynx.loadLazyBundle when using `import(/* relative path */)`. ([#1956](https://github.com/lynx-family/lynx-stack/pull/1956))
|
|
353
355
|
|
|
354
356
|
- feat: support declaring cross-thread shared modules via Import Attributes, enabling Main Thread Functions to call standard JS functions directly. ([#1968](https://github.com/lynx-family/lynx-stack/pull/1968))
|
|
355
|
-
|
|
356
357
|
- Usage: Add `with { runtime: "shared" }` to the `import` statement. For example:
|
|
357
358
|
|
|
358
359
|
```ts
|
|
359
|
-
import { func } from
|
|
360
|
+
import { func } from "./utils.js" with { runtime: "shared" };
|
|
360
361
|
|
|
361
362
|
function worklet() {
|
|
362
|
-
|
|
363
|
+
"main thread";
|
|
363
364
|
func(); // callable inside a main thread function
|
|
364
365
|
}
|
|
365
366
|
```
|
|
@@ -375,13 +376,11 @@
|
|
|
375
376
|
- **BREAKING CHANGE**: Delay the `createSnapshot` operation to `Snapshot` constructor to speed up IFR. ([#1899](https://github.com/lynx-family/lynx-stack/pull/1899))
|
|
376
377
|
|
|
377
378
|
This change refactors how snapshots are created and registered:
|
|
378
|
-
|
|
379
379
|
- Removed the `entryUniqID` function
|
|
380
380
|
- Snapshots are now lazily created via `snapshotCreatorMap` instead of eagerly at bundle load time
|
|
381
381
|
- Snapshot IDs are generated at compile time and only prefixed with `${globDynamicComponentEntry}:` for standalone lazy bundles
|
|
382
382
|
|
|
383
383
|
**⚠️ Lazy Bundle Compatibility:**
|
|
384
|
-
|
|
385
384
|
- **Backward compatibility (new runtime → old lazy bundles)**: ✅ **Supported**. Old lazy bundles will work with the new runtime.
|
|
386
385
|
|
|
387
386
|
- **Forward compatibility (old runtime → new lazy bundles)**: ❌ **NOT Supported**. Lower version consumers **will not be able to load lazy bundles produced by this version** due to the changed snapshot creation mechanism.
|
|
@@ -436,11 +435,11 @@
|
|
|
436
435
|
- Support testing React Compiler in testing library. Enable React Compiler by setting the `experimental_enableReactCompiler` option of `createVitestConfig` to `true`. ([#1269](https://github.com/lynx-family/lynx-stack/pull/1269))
|
|
437
436
|
|
|
438
437
|
```js
|
|
439
|
-
import { defineConfig, mergeConfig } from
|
|
440
|
-
import { createVitestConfig } from
|
|
438
|
+
import { defineConfig, mergeConfig } from "vitest/config";
|
|
439
|
+
import { createVitestConfig } from "@lynx-js/react/testing-library/vitest-config";
|
|
441
440
|
|
|
442
441
|
const defaultConfig = await createVitestConfig({
|
|
443
|
-
runtimePkgName:
|
|
442
|
+
runtimePkgName: "@lynx-js/react",
|
|
444
443
|
experimental_enableReactCompiler: true,
|
|
445
444
|
});
|
|
446
445
|
|
|
@@ -470,7 +469,7 @@
|
|
|
470
469
|
```tsx
|
|
471
470
|
function App() {
|
|
472
471
|
function handleInnerTap(event: MainThread.TouchEvent) {
|
|
473
|
-
|
|
472
|
+
"main thread";
|
|
474
473
|
event.stopPropagation();
|
|
475
474
|
// Or stop immediate propagation with
|
|
476
475
|
// event.stopImmediatePropagation();
|
|
@@ -568,10 +567,10 @@
|
|
|
568
567
|
- Add `animate` API in Main Thread Script(MTS), so you can now control a CSS animation imperatively ([#1534](https://github.com/lynx-family/lynx-stack/pull/1534))
|
|
569
568
|
|
|
570
569
|
```ts
|
|
571
|
-
import type { MainThread } from
|
|
570
|
+
import type { MainThread } from "@lynx-js/types";
|
|
572
571
|
|
|
573
572
|
function startAnimation(ele: MainThread.Element) {
|
|
574
|
-
|
|
573
|
+
"main thread";
|
|
575
574
|
const animation = ele.animate([{ opacity: 0 }, { opacity: 1 }], {
|
|
576
575
|
duration: 3000,
|
|
577
576
|
});
|
|
@@ -600,13 +599,12 @@
|
|
|
600
599
|
- Supports `recyclable` attribute in `<list-item>` to control whether the list item is recyclable. The `recyclable` attribute depends on Lynx Engine 3.4 or later. ([#1388](https://github.com/lynx-family/lynx-stack/pull/1388))
|
|
601
600
|
|
|
602
601
|
```jsx
|
|
603
|
-
<list-item recyclable={false}
|
|
602
|
+
<list-item recyclable={false} />
|
|
604
603
|
```
|
|
605
604
|
|
|
606
605
|
- feat: Support using a host element as direct child of Suspense ([#1455](https://github.com/lynx-family/lynx-stack/pull/1455))
|
|
607
606
|
|
|
608
607
|
- Add profile in production build: ([#1336](https://github.com/lynx-family/lynx-stack/pull/1336))
|
|
609
|
-
|
|
610
608
|
1. `diff:__COMPONENT_NAME__`: how long ReactLynx diff took.
|
|
611
609
|
2. `render:__COMPONENT_NAME__`: how long your render function took.
|
|
612
610
|
3. `setState`: an instant trace event, indicate when your setState was called.
|
|
@@ -621,7 +619,7 @@
|
|
|
621
619
|
|
|
622
620
|
```ts
|
|
623
621
|
function handleTap() {
|
|
624
|
-
|
|
622
|
+
"main thread";
|
|
625
623
|
// The following check always returned false before this fix
|
|
626
624
|
if (myHandleTap) {
|
|
627
625
|
runOnBackground(myHandleTap)();
|
|
@@ -644,7 +642,6 @@
|
|
|
644
642
|
- feat: Force synchronous rendering for background initial renders to support Suspense fallbacks ([#1323](https://github.com/lynx-family/lynx-stack/pull/1323))
|
|
645
643
|
|
|
646
644
|
- Introduces `@lynx-js/react/compat` submodule exporting Preact implementations of: ([#1316](https://github.com/lynx-family/lynx-stack/pull/1316))
|
|
647
|
-
|
|
648
645
|
- `startTransition`
|
|
649
646
|
- `useTransition`
|
|
650
647
|
|
|
@@ -682,10 +679,10 @@
|
|
|
682
679
|
Add the import to `@lynx-js/react/debug` at the first line of the entry:
|
|
683
680
|
|
|
684
681
|
```js
|
|
685
|
-
import
|
|
686
|
-
import { root } from
|
|
682
|
+
import "@lynx-js/react/debug";
|
|
683
|
+
import { root } from "@lynx-js/react";
|
|
687
684
|
|
|
688
|
-
import { App } from
|
|
685
|
+
import { App } from "./App.jsx";
|
|
689
686
|
|
|
690
687
|
root.render(<App />);
|
|
691
688
|
```
|
|
@@ -695,9 +692,9 @@
|
|
|
695
692
|
For example, you can use it like this:
|
|
696
693
|
|
|
697
694
|
```jsx
|
|
698
|
-
<list-item defer={{ unmountRecycled: true }} item-key=
|
|
695
|
+
<list-item defer={{ unmountRecycled: true }} item-key="1">
|
|
699
696
|
<WillBeUnmountIfRecycled />
|
|
700
|
-
</list-item
|
|
697
|
+
</list-item>
|
|
701
698
|
```
|
|
702
699
|
|
|
703
700
|
Now the component will be unmounted when it is recycled, which can help with performance in certain scenarios.
|
|
@@ -705,7 +702,7 @@
|
|
|
705
702
|
- Avoid some unexpected `__SetAttribute` in hydrate when `undefined` is passed as an attribute value to intrinsic elements, for example: ([#1318](https://github.com/lynx-family/lynx-stack/pull/1318))
|
|
706
703
|
|
|
707
704
|
```jsx
|
|
708
|
-
<image async-mode={undefined}
|
|
705
|
+
<image async-mode={undefined} />
|
|
709
706
|
```
|
|
710
707
|
|
|
711
708
|
## 0.111.1
|
|
@@ -744,14 +741,13 @@
|
|
|
744
741
|
- Fixed: An issue where the `lynxViewDidUpdate` callback did not trigger when data was updated from native. ([#1171](https://github.com/lynx-family/lynx-stack/pull/1171))
|
|
745
742
|
|
|
746
743
|
Notice:
|
|
747
|
-
|
|
748
744
|
- Even if no data changes are actually processed after calling `updateData()`, the `lynxViewDidUpdate` callback will still be triggered.
|
|
749
745
|
- Only one `lynxViewDidUpdate` callback will be triggered per render cycle. Consequently, if multiple `updateData()` calls are made within a single cycle but the data updates are batched, the number of `lynxViewDidUpdate` callbacks triggered may be less than the number of `updateData()` calls.
|
|
750
746
|
|
|
751
747
|
- Supports `act` in testing library. ([#1182](https://github.com/lynx-family/lynx-stack/pull/1182))
|
|
752
748
|
|
|
753
749
|
```js
|
|
754
|
-
import { act } from
|
|
750
|
+
import { act } from "@lynx-js/react/testing-library";
|
|
755
751
|
|
|
756
752
|
act(() => {
|
|
757
753
|
// ...
|
|
@@ -771,14 +767,12 @@
|
|
|
771
767
|
- Fixed closure variable capture issue in effect hooks to prevent stale values and ensured proper execution order between refs, effects, and event handlers. ([#770](https://github.com/lynx-family/lynx-stack/pull/770))
|
|
772
768
|
|
|
773
769
|
**Breaking Changes**:
|
|
774
|
-
|
|
775
770
|
- The execution timing of `ref`, `useEffect()` callback, `componentDidMount`, `componentDidUpdate`, `componentWillUnmount` and the callback of `setState` have been moved forward. These effects will now execute before hydration is complete, rather than waiting for the main thread update to complete.
|
|
776
771
|
- For components inside `<list />`, `ref` callbacks will now be triggered during background thread rendering, regardless of component visibility. If your code depends on component visibility timing, use `main-thread:ref` instead of regular `ref`.
|
|
777
772
|
|
|
778
773
|
### Patch Changes
|
|
779
774
|
|
|
780
775
|
- Fixed two memory leaks: ([#1071](https://github.com/lynx-family/lynx-stack/pull/1071))
|
|
781
|
-
|
|
782
776
|
1. When JSX is rendered on the main thread and removed, FiberElement can still be referenced by `__root.__jsx` through `props.children`;
|
|
783
777
|
|
|
784
778
|
2. When the SnapshotInstance tree is removed from the root node, its child nodes form a cycle reference because the `__previousSibling` and `__nextSibling` properties point to each other, thus causing a FiberElement leak.
|
|
@@ -857,8 +851,7 @@
|
|
|
857
851
|
* 3: Full Resolution - Batch render with async property and element tree resolution for list item subtree
|
|
858
852
|
*/
|
|
859
853
|
experimental-batch-render-strategy={3}
|
|
860
|
-
>
|
|
861
|
-
</list>;
|
|
854
|
+
></list>
|
|
862
855
|
```
|
|
863
856
|
|
|
864
857
|
- rename @lynx-js/test-environment to @lynx-js/testing-environment ([#704](https://github.com/lynx-family/lynx-stack/pull/704))
|
|
@@ -884,7 +877,6 @@
|
|
|
884
877
|
### Minor Changes
|
|
885
878
|
|
|
886
879
|
- Some of the timing keys are renamed to match the naming convention of the Lynx Engine. ([#438](https://github.com/lynx-family/lynx-stack/pull/438))
|
|
887
|
-
|
|
888
880
|
- `update_set_state_trigger` -> `updateSetStateTrigger`
|
|
889
881
|
- `update_diff_vdom_start` -> `updateDiffVdomStart`
|
|
890
882
|
- `update_diff_vdom_end` -> `updateDiffVdomEnd`
|
|
@@ -976,7 +968,7 @@
|
|
|
976
968
|
You can now use `useErrorBoundary` it in TypeScript like this:
|
|
977
969
|
|
|
978
970
|
```tsx
|
|
979
|
-
import { useErrorBoundary } from
|
|
971
|
+
import { useErrorBoundary } from "@lynx-js/react";
|
|
980
972
|
```
|
|
981
973
|
|
|
982
974
|
- Modified the format of data sent from background threads to the main thread. ([#207](https://github.com/lynx-family/lynx-stack/pull/207))
|
|
@@ -1028,13 +1020,13 @@
|
|
|
1028
1020
|
Now you can get the return value from `runOnBackground()` and `runOnMainThread()`, which enables more flexible data flow between the main thread and the background thread.
|
|
1029
1021
|
|
|
1030
1022
|
```js
|
|
1031
|
-
import { runOnBackground } from
|
|
1023
|
+
import { runOnBackground } from "@lynx-js/react";
|
|
1032
1024
|
|
|
1033
1025
|
const onTap = async () => {
|
|
1034
|
-
|
|
1026
|
+
"main thread";
|
|
1035
1027
|
const text = await runOnBackground(() => {
|
|
1036
|
-
|
|
1037
|
-
return
|
|
1028
|
+
"background only";
|
|
1029
|
+
return "Hello, world!";
|
|
1038
1030
|
})();
|
|
1039
1031
|
console.log(text);
|
|
1040
1032
|
};
|
|
@@ -1069,9 +1061,9 @@
|
|
|
1069
1061
|
|
|
1070
1062
|
```ts
|
|
1071
1063
|
// These imports will be removed from the final bundle
|
|
1072
|
-
import type { Foo } from
|
|
1073
|
-
import { type Bar } from
|
|
1074
|
-
import { xyz } from
|
|
1064
|
+
import type { Foo } from "xyz";
|
|
1065
|
+
import { type Bar } from "xyz";
|
|
1066
|
+
import { xyz } from "xyz"; // When xyz is not used
|
|
1075
1067
|
```
|
|
1076
1068
|
|
|
1077
1069
|
See [TypeScript - verbatimModuleSyntax](https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax) for details.
|
|
@@ -1111,7 +1103,7 @@
|
|
|
1111
1103
|
const f = undefined;
|
|
1112
1104
|
|
|
1113
1105
|
function mts() {
|
|
1114
|
-
|
|
1106
|
+
"main thread";
|
|
1115
1107
|
// throws in background rendering
|
|
1116
1108
|
f && runOnBackground(f)();
|
|
1117
1109
|
}
|
|
@@ -1145,14 +1137,14 @@
|
|
|
1145
1137
|
- a30c83d: Add `compat.removeComponentAttrRegex`.
|
|
1146
1138
|
|
|
1147
1139
|
```js
|
|
1148
|
-
import { pluginReactLynx } from
|
|
1149
|
-
import { defineConfig } from
|
|
1140
|
+
import { pluginReactLynx } from "@lynx-js/react-rsbuild-plugin";
|
|
1141
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
1150
1142
|
|
|
1151
1143
|
export default defineConfig({
|
|
1152
1144
|
plugins: [
|
|
1153
1145
|
pluginReactLynx({
|
|
1154
1146
|
compat: {
|
|
1155
|
-
removeComponentAttrRegex:
|
|
1147
|
+
removeComponentAttrRegex: "YOUR REGEX",
|
|
1156
1148
|
},
|
|
1157
1149
|
}),
|
|
1158
1150
|
],
|
|
@@ -1229,7 +1221,6 @@
|
|
|
1229
1221
|
</table>
|
|
1230
1222
|
|
|
1231
1223
|
This requires `@lynx-js/react-rsbuild-plugin` v0.5.1 to work.
|
|
1232
|
-
|
|
1233
1224
|
- Inject `globDynamicComponentEntry` for background script. ([#311](https://github.com/lynx-wg/lynx-stack/pull/311))
|
|
1234
1225
|
- Inject `globDynamicComponentEntry` for main thread script. ([#312](https://github.com/lynx-wg/lynx-stack/pull/312))
|
|
1235
1226
|
|
|
@@ -1238,22 +1229,22 @@
|
|
|
1238
1229
|
Gesture Handler is a set of gesture handling capabilities built on top of the Main Thread Script. It currently supports drag, inertial scrolling, long press, and tap gestures for `<view>`, `<scroll-view>`, `<list>`, and `<text>`. In the future, it will also support multi-finger zoom, multi-finger rotation, and other gesture capabilities.
|
|
1239
1230
|
|
|
1240
1231
|
```tsx
|
|
1241
|
-
import { useGesture, PanGesture } from
|
|
1232
|
+
import { useGesture, PanGesture } from "@lynx-js/gesture-runtime";
|
|
1242
1233
|
|
|
1243
1234
|
function App() {
|
|
1244
1235
|
const pan = useGesture(PanGesture);
|
|
1245
1236
|
|
|
1246
1237
|
pan
|
|
1247
1238
|
.onBegin((event, stateManager) => {
|
|
1248
|
-
|
|
1239
|
+
"main thread";
|
|
1249
1240
|
// some logic
|
|
1250
1241
|
})
|
|
1251
1242
|
.onUpdate((event, stateManager) => {
|
|
1252
|
-
|
|
1243
|
+
"main thread";
|
|
1253
1244
|
// some logic
|
|
1254
1245
|
})
|
|
1255
1246
|
.onEnd((event, stateManager) => {
|
|
1256
|
-
|
|
1247
|
+
"main thread";
|
|
1257
1248
|
// some logic
|
|
1258
1249
|
});
|
|
1259
1250
|
|
|
@@ -1273,7 +1264,7 @@
|
|
|
1273
1264
|
return;
|
|
1274
1265
|
}
|
|
1275
1266
|
|
|
1276
|
-
console.log(
|
|
1267
|
+
console.log("not __LEPUS__"); // This can be removed now
|
|
1277
1268
|
}
|
|
1278
1269
|
```
|
|
1279
1270
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IndexMap } from '../../shared/index-map.js';
|
|
2
|
+
import type { JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Keeps the background-thread worklet ctx alive while main thread still holds
|
|
5
|
+
* a handle to one of its background functions.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BackgroundFunctionExecMap extends IndexMap<Worklet> {
|
|
8
|
+
add(worklet: Worklet): number;
|
|
9
|
+
findJsFnHandle(execId: number, fnId: number): JsFnHandle | undefined;
|
|
10
|
+
private findJsFnHandleInValue;
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { IndexMap } from '../../shared/index-map.js';
|
|
5
|
+
/**
|
|
6
|
+
* Keeps the background-thread worklet ctx alive while main thread still holds
|
|
7
|
+
* a handle to one of its background functions.
|
|
8
|
+
*/
|
|
9
|
+
export class BackgroundFunctionExecMap extends IndexMap {
|
|
10
|
+
add(worklet) {
|
|
11
|
+
const execId = super.add(worklet);
|
|
12
|
+
worklet._execId = execId;
|
|
13
|
+
return execId;
|
|
14
|
+
}
|
|
15
|
+
findJsFnHandle(execId, fnId) {
|
|
16
|
+
const worklet = this.get(execId);
|
|
17
|
+
if (!worklet) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return this.findJsFnHandleInValue(worklet, fnId);
|
|
21
|
+
}
|
|
22
|
+
findJsFnHandleInValue(value, fnId) {
|
|
23
|
+
if (value === null || typeof value !== 'object') {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const obj = value;
|
|
27
|
+
if ('_jsFnId' in obj && obj['_jsFnId'] === fnId) {
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
for (const i in obj) {
|
|
31
|
+
const result = this.findJsFnHandleInValue(obj[i], fnId);
|
|
32
|
+
if (result) {
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=exec-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec-map.js","sourceRoot":"","sources":["../../../src/core/background-function/exec-map.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD;;;GAGG;AACH,MAAM,OAAO,yBAA0B,SAAQ,QAAiB;IAC9C,GAAG,CAAC,OAAgB;QAClC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;QACzB,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,cAAc,CAAC,MAAc,EAAE,IAAY;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAEO,qBAAqB,CAAC,KAAc,EAAE,IAAY;QACxD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAChD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,GAAG,GAAG,KAAgC,CAAC;QAC7C,IAAI,SAAS,IAAI,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;YAChD,OAAO,GAAiB,CAAC;QAC3B,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;YACxD,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JsFnHandle } from '../../worklet-runtime/bindings/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the serializable handle used by main-thread code to call a background function.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createBackgroundFunctionHandle(obj: ((...args: any[]) => any) & {
|
|
6
|
+
toJSON?: () => string;
|
|
7
|
+
}): JsFnHandle;
|
|
8
|
+
export declare function resetBackgroundFunctionHandleIdForTesting(): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
let lastId = 0;
|
|
5
|
+
/**
|
|
6
|
+
* Creates the serializable handle used by main-thread code to call a background function.
|
|
7
|
+
*/
|
|
8
|
+
export function createBackgroundFunctionHandle(obj) {
|
|
9
|
+
const id = ++lastId;
|
|
10
|
+
if (typeof obj !== 'function') {
|
|
11
|
+
return {
|
|
12
|
+
_jsFnId: id,
|
|
13
|
+
_error: `Argument of runOnBackground should be a function, but got [${typeof obj}] instead`,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
obj.toJSON ??= () => '[BackgroundFunction]';
|
|
17
|
+
return {
|
|
18
|
+
_jsFnId: id,
|
|
19
|
+
_fn: obj,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function resetBackgroundFunctionHandleIdForTesting() {
|
|
23
|
+
lastId = 0;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../../src/core/background-function/handle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC5C,GAA0D;IAE1D,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC;IACpB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO;YACL,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,8DAA8D,OAAO,GAAG,WAAW;SAC5F,CAAC;IACJ,CAAC;IACD,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC,sBAAsB,CAAC;IAC5C,OAAO;QACL,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,GAAG;KACT,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yCAAyC;IACvD,MAAM,GAAG,CAAC,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function resetBackgroundFunctionRuntime(): void;
|
|
2
|
+
/**
|
|
3
|
+
* `runOnBackground` allows triggering js functions on the background thread asynchronously.
|
|
4
|
+
* @param f - The js function to be called.
|
|
5
|
+
* @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare function runOnBackground<R, Fn extends (...args: any[]) => R>(f: Fn): (...args: Parameters<Fn>) => Promise<R>;
|
|
@@ -1,30 +1,35 @@
|
|
|
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 {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { BackgroundFunctionExecMap } from './exec-map.js';
|
|
5
|
+
import { isSdkVersionGt } from '../../utils.js';
|
|
6
|
+
import { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
|
|
7
|
+
import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
|
|
8
|
+
import { registerDestroyTask } from '../runtime-destroy.js';
|
|
9
|
+
import { onFunctionCall } from '../thread-function-call/return-value.js';
|
|
9
10
|
let execIdMap;
|
|
10
|
-
|
|
11
|
+
let cleanupBackgroundFunctionRuntime;
|
|
12
|
+
let unregisterBackgroundFunctionCleanup;
|
|
13
|
+
function initBackgroundFunctionRuntime() {
|
|
11
14
|
'background only';
|
|
12
15
|
if (execIdMap) {
|
|
13
16
|
return;
|
|
14
17
|
}
|
|
15
|
-
execIdMap = new
|
|
16
|
-
lynx.getCoreContext()
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
execIdMap = new BackgroundFunctionExecMap();
|
|
19
|
+
const context = lynx.getCoreContext();
|
|
20
|
+
context.addEventListener(WorkletEvents.runOnBackground, runBackgroundFunction);
|
|
21
|
+
context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);
|
|
22
|
+
cleanupBackgroundFunctionRuntime = () => {
|
|
23
|
+
context.removeEventListener(WorkletEvents.runOnBackground, runBackgroundFunction);
|
|
24
|
+
context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);
|
|
21
25
|
execIdMap = undefined;
|
|
22
|
-
|
|
26
|
+
cleanupBackgroundFunctionRuntime = undefined;
|
|
27
|
+
};
|
|
23
28
|
}
|
|
24
29
|
/**
|
|
25
30
|
* @internal
|
|
26
31
|
*/
|
|
27
|
-
function
|
|
32
|
+
export function runBackgroundFunction(event) {
|
|
28
33
|
'background only';
|
|
29
34
|
const data = JSON.parse(event.data);
|
|
30
35
|
const obj = execIdMap.findJsFnHandle(data.obj._execId, data.obj._jsFnId);
|
|
@@ -41,7 +46,7 @@ function runJSFunction(event) {
|
|
|
41
46
|
}),
|
|
42
47
|
});
|
|
43
48
|
}
|
|
44
|
-
function
|
|
49
|
+
function releaseBackgroundFunctionCtx(event) {
|
|
45
50
|
'background only';
|
|
46
51
|
for (const id of event.data) {
|
|
47
52
|
execIdMap.remove(id);
|
|
@@ -50,31 +55,33 @@ function releaseBackgroundWorkletCtx(event) {
|
|
|
50
55
|
/**
|
|
51
56
|
* @internal
|
|
52
57
|
*/
|
|
53
|
-
function
|
|
58
|
+
export function registerBackgroundFunctionCtx(ctx) {
|
|
54
59
|
'background only';
|
|
55
|
-
|
|
60
|
+
initBackgroundFunctionRuntime();
|
|
61
|
+
ensureBackgroundFunctionCleanup();
|
|
56
62
|
execIdMap.add(ctx);
|
|
57
63
|
}
|
|
64
|
+
function ensureBackgroundFunctionCleanup() {
|
|
65
|
+
if (unregisterBackgroundFunctionCleanup) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
unregisterBackgroundFunctionCleanup = registerDestroyTask(() => {
|
|
69
|
+
resetBackgroundFunctionRuntime();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export function resetBackgroundFunctionRuntime() {
|
|
73
|
+
cleanupBackgroundFunctionRuntime?.();
|
|
74
|
+
unregisterBackgroundFunctionCleanup?.();
|
|
75
|
+
unregisterBackgroundFunctionCleanup = undefined;
|
|
76
|
+
}
|
|
58
77
|
/**
|
|
59
78
|
* `runOnBackground` allows triggering js functions on the background thread asynchronously.
|
|
60
79
|
* @param f - The js function to be called.
|
|
61
80
|
* @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* import { runOnBackground } from '@lynx-js/react';
|
|
65
|
-
*
|
|
66
|
-
* async function someMainthreadFunction() {
|
|
67
|
-
* 'main thread';
|
|
68
|
-
* const fn = runOnBackground(() => {
|
|
69
|
-
* return 'hello';
|
|
70
|
-
* });
|
|
71
|
-
* const result = await fn();
|
|
72
|
-
}
|
|
73
|
-
* ```
|
|
74
81
|
* @public
|
|
75
82
|
*/
|
|
76
|
-
function runOnBackground(f) {
|
|
77
|
-
if (!
|
|
83
|
+
export function runOnBackground(f) {
|
|
84
|
+
if (!isSdkVersionGt(2, 15)) {
|
|
78
85
|
throw new Error('runOnBackground requires Lynx sdk version 2.16.');
|
|
79
86
|
}
|
|
80
87
|
if (__JS__) {
|
|
@@ -110,5 +117,4 @@ function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId) {
|
|
|
110
117
|
}),
|
|
111
118
|
});
|
|
112
119
|
}
|
|
113
|
-
|
|
114
|
-
//# sourceMappingURL=runOnBackground.js.map
|
|
120
|
+
//# sourceMappingURL=run-on-background.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-on-background.js","sourceRoot":"","sources":["../../../src/core/background-function/run-on-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC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