@lynx-js/react 0.110.1 → 0.111.1

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/components/lib/DeferredListItem.d.ts +7 -0
  3. package/components/lib/DeferredListItem.jsx +40 -0
  4. package/components/lib/DeferredListItem.jsx.map +1 -0
  5. package/components/lib/index.d.ts +1 -0
  6. package/components/lib/index.js +1 -0
  7. package/components/lib/index.js.map +1 -1
  8. package/components/src/DeferredListItem.tsx +56 -0
  9. package/components/src/index.ts +1 -0
  10. package/package.json +1 -1
  11. package/refresh/.turbo/turbo-build.log +7 -3
  12. package/refresh/dist/index.js +223 -284
  13. package/refresh/package.json +3 -4
  14. package/refresh/rslib.config.ts +24 -0
  15. package/runtime/lazy/react-lepus.js +1 -0
  16. package/runtime/lazy/react.js +1 -0
  17. package/runtime/lepus/index.d.ts +1 -1
  18. package/runtime/lepus/index.js +44 -0
  19. package/runtime/lib/backgroundSnapshot.d.ts +2 -1
  20. package/runtime/lib/backgroundSnapshot.js +62 -40
  21. package/runtime/lib/backgroundSnapshot.js.map +1 -1
  22. package/runtime/lib/compat/initData.js +10 -0
  23. package/runtime/lib/compat/initData.js.map +1 -1
  24. package/runtime/lib/index.d.ts +2 -2
  25. package/runtime/lib/index.js +2 -2
  26. package/runtime/lib/index.js.map +1 -1
  27. package/runtime/lib/lifecycle/patch/commit.js +5 -5
  28. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  29. package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +9 -9
  30. package/runtime/lib/lifecycle/patch/snapshotPatch.js +9 -10
  31. package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
  32. package/runtime/lib/lifecycle/patch/updateMainThread.js +7 -8
  33. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  34. package/runtime/lib/lifecycleConstant.d.ts +2 -1
  35. package/runtime/lib/lifecycleConstant.js +1 -0
  36. package/runtime/lib/lifecycleConstant.js.map +1 -1
  37. package/runtime/lib/list.js +102 -12
  38. package/runtime/lib/list.js.map +1 -1
  39. package/runtime/lib/lynx/calledByNative.js +6 -9
  40. package/runtime/lib/lynx/calledByNative.js.map +1 -1
  41. package/runtime/lib/lynx/component.js +11 -14
  42. package/runtime/lib/lynx/component.js.map +1 -1
  43. package/runtime/lib/lynx/env.js +1 -2
  44. package/runtime/lib/lynx/env.js.map +1 -1
  45. package/runtime/lib/lynx/lazy-bundle.js +48 -21
  46. package/runtime/lib/lynx/lazy-bundle.js.map +1 -1
  47. package/runtime/lib/lynx/performance.d.ts +3 -19
  48. package/runtime/lib/lynx/performance.js +25 -26
  49. package/runtime/lib/lynx/performance.js.map +1 -1
  50. package/runtime/lib/lynx/tt.js +10 -5
  51. package/runtime/lib/lynx/tt.js.map +1 -1
  52. package/runtime/lib/lynx-api.d.ts +78 -1
  53. package/runtime/lib/lynx-api.js.map +1 -1
  54. package/runtime/lib/snapshot.d.ts +2 -0
  55. package/runtime/lib/snapshot.js +19 -5
  56. package/runtime/lib/snapshot.js.map +1 -1
  57. package/runtime/lib/utils.d.ts +1 -0
  58. package/runtime/lib/utils.js +6 -0
  59. package/runtime/lib/utils.js.map +1 -1
  60. package/runtime/src/backgroundSnapshot.ts +74 -55
  61. package/runtime/src/compat/initData.ts +10 -0
  62. package/runtime/src/index.ts +2 -0
  63. package/runtime/src/lifecycle/patch/commit.ts +5 -11
  64. package/runtime/src/lifecycle/patch/snapshotPatch.ts +9 -9
  65. package/runtime/src/lifecycle/patch/updateMainThread.ts +7 -8
  66. package/runtime/src/lifecycleConstant.ts +1 -0
  67. package/runtime/src/list.ts +118 -15
  68. package/runtime/src/lynx/calledByNative.ts +6 -8
  69. package/runtime/src/lynx/component.ts +17 -29
  70. package/runtime/src/lynx/env.ts +1 -2
  71. package/runtime/src/lynx/lazy-bundle.ts +55 -20
  72. package/runtime/src/lynx/performance.ts +26 -27
  73. package/runtime/src/lynx/tt.ts +10 -11
  74. package/runtime/src/lynx-api.ts +77 -1
  75. package/runtime/src/snapshot.ts +20 -5
  76. package/runtime/src/utils.ts +9 -0
  77. package/testing-library/dist/env/vitest.js +6 -3
  78. package/testing-library/dist/index.d.ts +4 -1
  79. package/testing-library/dist/pure.js +4 -2
  80. package/testing-library/dist/vitest-global-setup.js +2 -2
  81. package/testing-library/dist/vitest.config.js +38 -1
  82. package/testing-library/types/entry.d.ts +3 -2
  83. package/transform/dist/wasm.cjs +1 -1
  84. package/types/react.d.ts +21 -1
  85. package/types/react.docs.d.ts +1 -1
  86. package/worklet-runtime/dist/dev.js +403 -506
  87. package/worklet-runtime/dist/main.js +1 -517
  88. package/worklet-runtime/lib/workletRuntime.js +5 -5
  89. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # @lynx-js/react
2
2
 
3
+ ## 0.111.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Wrap the main thread `renderPage` in preact `act` to ensure that the effects are flushed. ([#1170](https://github.com/lynx-family/lynx-stack/pull/1170))
8
+
9
+ ## 0.111.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Allow some `<list-item/>`s to be deferred and rendered in the background thread. ([#204](https://github.com/lynx-family/lynx-stack/pull/204))
14
+
15
+ Use the following syntax:
16
+
17
+ ```diff
18
+ <list>
19
+ - <list-item item-key="...">
20
+ + <list-item item-key="..." defer>
21
+ <SomeHeavyComponent />
22
+ </list-item>
23
+ </list>
24
+ ```
25
+
26
+ You should render your heavyweight components with the `defer` attribute to avoid blocking the main thread.
27
+
28
+ ### Patch Changes
29
+
30
+ - Add missing alias of `@lynx-js/react` and `preact` in testing library, it will fix the `Failed to resolve import "@lynx-js/react/internal"` error in node_modules. ([#1182](https://github.com/lynx-family/lynx-stack/pull/1182))
31
+
32
+ - Allow any types of `dataProcessors` in `lynx.registerDataProcessors`. ([#1200](https://github.com/lynx-family/lynx-stack/pull/1200))
33
+
34
+ - Make `loadLazyBundle` being able to render the content on the first screen of the background thread. ([#1212](https://github.com/lynx-family/lynx-stack/pull/1212))
35
+
36
+ - 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))
37
+
38
+ Notice:
39
+
40
+ - Even if no data changes are actually processed after calling `updateData()`, the `lynxViewDidUpdate` callback will still be triggered.
41
+ - 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.
42
+
43
+ - Supports `act` in testing library. ([#1182](https://github.com/lynx-family/lynx-stack/pull/1182))
44
+
45
+ ```js
46
+ import { act } from '@lynx-js/react/testing-library';
47
+
48
+ act(() => {
49
+ // ...
50
+ });
51
+ ```
52
+
3
53
  ## 0.110.1
4
54
 
5
55
  ### Patch Changes
@@ -0,0 +1,7 @@
1
+ import type { FC, ReactNode } from 'react';
2
+ export interface DeferredListItemProps {
3
+ defer?: boolean;
4
+ renderListItem: (children: ReactNode | undefined) => JSX.Element;
5
+ renderChildren: () => ReactNode;
6
+ }
7
+ export declare const DeferredListItem: FC<DeferredListItemProps>;
@@ -0,0 +1,40 @@
1
+ // Copyright 2025 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 { cloneElement as _cloneElement, useCallback, useRef, useState } from '@lynx-js/react';
5
+ import { cloneElement as _cloneElementMainThread } from '@lynx-js/react/lepus';
6
+ export const DeferredListItem = ({ defer, renderListItem, renderChildren }) => {
7
+ const __cloneElement = __MAIN_THREAD__ ? _cloneElementMainThread : _cloneElement;
8
+ const initialDeferRef = useRef(defer);
9
+ const prevDeferRef = useRef(defer);
10
+ const [isReady, setIsReady] = useState(!defer);
11
+ const onGetSnapshotInstance = useCallback((ctx) => {
12
+ 'background only';
13
+ ctx.__extraProps ??= {};
14
+ // hack: preact ignore function property on dom
15
+ ctx.__extraProps['onComponentAtIndex'] = () => {
16
+ setIsReady(true);
17
+ };
18
+ ctx.__extraProps['onRecycleComponent'] = () => {
19
+ // TODO(hzy): figure out if we need to unmount the component when recycled
20
+ // setIsReady(false);
21
+ };
22
+ return () => {
23
+ delete ctx.__extraProps['onComponentAtIndex'];
24
+ delete ctx.__extraProps['onRecycleComponent'];
25
+ };
26
+ }, []);
27
+ if (__BACKGROUND__) {
28
+ if (prevDeferRef.current && !defer) {
29
+ setIsReady(true);
30
+ }
31
+ prevDeferRef.current = defer;
32
+ }
33
+ return initialDeferRef.current
34
+ ? __cloneElement(renderListItem(isReady ? renderChildren() : null), {
35
+ isReady: +isReady, // hack: preact specially handled boolean props
36
+ ref: onGetSnapshotInstance,
37
+ })
38
+ : renderListItem(renderChildren());
39
+ };
40
+ //# sourceMappingURL=DeferredListItem.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeferredListItem.jsx","sourceRoot":"","sources":["../src/DeferredListItem.tsx"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,OAAO,EAAE,YAAY,IAAI,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE9F,OAAO,EAAE,YAAY,IAAI,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAQ/E,MAAM,CAAC,MAAM,gBAAgB,GAA8B,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,EAAE,EAAE;IACvG,MAAM,cAAc,GAAG,eAAe,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,aAAa,CAAC;IAEjF,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,qBAAqB,GAAG,WAAW,CAAgC,CAAC,GAAG,EAAE,EAAE;QAC/E,iBAAiB,CAAC;QAElB,GAAI,CAAC,YAAY,KAAK,EAAE,CAAC;QAEzB,+CAA+C;QAC/C,GAAI,CAAC,YAAY,CAAC,oBAAoB,CAAC,GAAG,GAAG,EAAE;YAC7C,UAAU,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC;QACF,GAAI,CAAC,YAAY,CAAC,oBAAoB,CAAC,GAAG,GAAG,EAAE;YAC7C,0EAA0E;YAC1E,qBAAqB;QACvB,CAAC,CAAC;QAEF,OAAO,GAAG,EAAE;YACV,OAAO,GAAI,CAAC,YAAa,CAAC,oBAAoB,CAAC,CAAC;YAChD,OAAO,GAAI,CAAC,YAAa,CAAC,oBAAoB,CAAC,CAAC;QAClD,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,YAAY,CAAC,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;YACnC,UAAU,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;QACD,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;IAC/B,CAAC;IAED,OAAO,eAAe,CAAC,OAAO;QAC5B,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE;YAClE,OAAO,EAAE,CAAC,OAAO,EAAE,+CAA+C;YAClE,GAAG,EAAE,qBAAqB;SAC3B,CAAC;QACF,CAAC,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC;AACvC,CAAC,CAAC"}
@@ -1 +1,2 @@
1
1
  export { Page } from './Page.js';
2
+ export { DeferredListItem } from './DeferredListItem.jsx';
@@ -2,4 +2,5 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  export { Page } from './Page.js';
5
+ export { DeferredListItem } from './DeferredListItem.jsx';
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,56 @@
1
+ // Copyright 2025 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, ReactNode, RefCallback } from 'react';
6
+
7
+ import { cloneElement as _cloneElement, useCallback, useRef, useState } from '@lynx-js/react';
8
+ import type { SnapshotInstance } from '@lynx-js/react/internal';
9
+ import { cloneElement as _cloneElementMainThread } from '@lynx-js/react/lepus';
10
+
11
+ export interface DeferredListItemProps {
12
+ defer?: boolean;
13
+ renderListItem: (children: ReactNode | undefined) => JSX.Element;
14
+ renderChildren: () => ReactNode;
15
+ }
16
+
17
+ export const DeferredListItem: FC<DeferredListItemProps> = ({ defer, renderListItem, renderChildren }) => {
18
+ const __cloneElement = __MAIN_THREAD__ ? _cloneElementMainThread : _cloneElement;
19
+
20
+ const initialDeferRef = useRef(defer);
21
+ const prevDeferRef = useRef(defer);
22
+ const [isReady, setIsReady] = useState(!defer);
23
+ const onGetSnapshotInstance = useCallback<RefCallback<SnapshotInstance>>((ctx) => {
24
+ 'background only';
25
+
26
+ ctx!.__extraProps ??= {};
27
+
28
+ // hack: preact ignore function property on dom
29
+ ctx!.__extraProps['onComponentAtIndex'] = () => {
30
+ setIsReady(true);
31
+ };
32
+ ctx!.__extraProps['onRecycleComponent'] = () => {
33
+ // TODO(hzy): figure out if we need to unmount the component when recycled
34
+ // setIsReady(false);
35
+ };
36
+
37
+ return () => {
38
+ delete ctx!.__extraProps!['onComponentAtIndex'];
39
+ delete ctx!.__extraProps!['onRecycleComponent'];
40
+ };
41
+ }, []);
42
+
43
+ if (__BACKGROUND__) {
44
+ if (prevDeferRef.current && !defer) {
45
+ setIsReady(true);
46
+ }
47
+ prevDeferRef.current = defer;
48
+ }
49
+
50
+ return initialDeferRef.current
51
+ ? __cloneElement(renderListItem(isReady ? renderChildren() : null), {
52
+ isReady: +isReady, // hack: preact specially handled boolean props
53
+ ref: onGetSnapshotInstance,
54
+ })
55
+ : renderListItem(renderChildren());
56
+ };
@@ -3,3 +3,4 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
5
  export { Page } from './Page.js';
6
+ export { DeferredListItem } from './DeferredListItem.jsx';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/react",
3
- "version": "0.110.1",
3
+ "version": "0.111.1",
4
4
  "description": "ReactLynx is a framework for developing Lynx applications with familiar React.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,8 +1,12 @@
1
1
 
2
2
  > @lynx-js/react-refresh@0.1.0 build /home/runner/work/lynx-stack/lynx-stack/packages/react/refresh
3
- > esbuild --bundle src/index.ts --outfile=dist/index.js --external:@lynx-js/react --define:self=globalThis --format=esm --alias:preact=@lynx-js/react/internal --alias:preact/hooks=@lynx-js/react
3
+ > rslib build
4
4
 
5
+ Rslib v0.10.5
5
6
 
6
- dist/index.js 11.4kb
7
+ info build started...
8
+ ready built in 0.18 s
9
+
10
+ File (esm) Size 
11
+ dist/index.js 10.5 kB
7
12
 
8
- ⚡ Done in 22ms