@lynx-js/react 0.112.6 → 0.114.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/package.json +3 -3
  3. package/refresh/.turbo/turbo-build.log +2 -2
  4. package/runtime/lazy/internal.js +2 -0
  5. package/runtime/lib/internal.d.ts +4 -3
  6. package/runtime/lib/internal.js +4 -3
  7. package/runtime/lib/internal.js.map +1 -1
  8. package/runtime/lib/lifecycle/isRendering.d.ts +3 -0
  9. package/runtime/lib/lifecycle/isRendering.js +25 -0
  10. package/runtime/lib/lifecycle/isRendering.js.map +1 -0
  11. package/runtime/lib/lifecycle/patch/commit.d.ts +2 -1
  12. package/runtime/lib/lifecycle/patch/commit.js +9 -6
  13. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  14. package/runtime/lib/lifecycle/patch/updateMainThread.js +17 -4
  15. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  16. package/runtime/lib/lifecycle/ref/delay.d.ts +9 -4
  17. package/runtime/lib/lifecycle/ref/delay.js +23 -16
  18. package/runtime/lib/lifecycle/ref/delay.js.map +1 -1
  19. package/runtime/lib/lifecycle/reload.js +0 -2
  20. package/runtime/lib/lifecycle/reload.js.map +1 -1
  21. package/runtime/lib/lifecycleConstant.d.ts +2 -1
  22. package/runtime/lib/lifecycleConstant.js +1 -0
  23. package/runtime/lib/lifecycleConstant.js.map +1 -1
  24. package/runtime/lib/list.js +7 -2
  25. package/runtime/lib/list.js.map +1 -1
  26. package/runtime/lib/lynx/tt.js +6 -0
  27. package/runtime/lib/lynx/tt.js.map +1 -1
  28. package/runtime/lib/lynx-api.d.ts +3 -3
  29. package/runtime/lib/lynx-api.js +3 -3
  30. package/runtime/lib/lynx-api.js.map +1 -1
  31. package/runtime/lib/lynx.js +4 -7
  32. package/runtime/lib/lynx.js.map +1 -1
  33. package/runtime/lib/snapshot/spread.js +3 -3
  34. package/runtime/lib/snapshot/spread.js.map +1 -1
  35. package/runtime/lib/utils.d.ts +1 -0
  36. package/runtime/lib/utils.js +24 -0
  37. package/runtime/lib/utils.js.map +1 -1
  38. package/runtime/lib/worklet/call/delayedRunOnMainThreadData.d.ts +3 -0
  39. package/runtime/lib/worklet/call/delayedRunOnMainThreadData.js +10 -0
  40. package/runtime/lib/worklet/call/delayedRunOnMainThreadData.js.map +1 -0
  41. package/runtime/lib/worklet/{execMap.js → call/execMap.js} +1 -1
  42. package/runtime/lib/worklet/call/execMap.js.map +1 -0
  43. package/runtime/lib/worklet/{functionCall.js → call/functionCall.js} +2 -2
  44. package/runtime/lib/worklet/call/functionCall.js.map +1 -0
  45. package/runtime/lib/worklet/{runOnBackground.js → call/runOnBackground.js} +2 -2
  46. package/runtime/lib/worklet/call/runOnBackground.js.map +1 -0
  47. package/runtime/lib/worklet/{runOnMainThread.js → call/runOnMainThread.js} +16 -7
  48. package/runtime/lib/worklet/call/runOnMainThread.js.map +1 -0
  49. package/runtime/lib/worklet/call/transformToWorklet.js.map +1 -0
  50. package/runtime/lib/worklet/ctx.js +1 -1
  51. package/runtime/lib/worklet/ctx.js.map +1 -1
  52. package/runtime/lib/worklet/destroy.js +4 -2
  53. package/runtime/lib/worklet/destroy.js.map +1 -1
  54. package/runtime/lib/worklet/ref/updateInitValue.d.ts +2 -0
  55. package/runtime/lib/worklet/ref/updateInitValue.js +24 -0
  56. package/runtime/lib/worklet/ref/updateInitValue.js.map +1 -0
  57. package/runtime/lib/worklet/{workletRef.js → ref/workletRef.js} +1 -1
  58. package/runtime/lib/worklet/ref/workletRef.js.map +1 -0
  59. package/runtime/lib/worklet/ref/workletRefPool.d.ts +1 -0
  60. package/runtime/lib/worklet/{workletRefPool.js → ref/workletRefPool.js} +1 -3
  61. package/runtime/lib/worklet/ref/workletRefPool.js.map +1 -0
  62. package/testing-library/dist/env/vitest.js +2 -1
  63. package/testing-library/dist/index.d.ts +25 -2
  64. package/testing-library/dist/pure.js +21 -9
  65. package/testing-library/dist/vitest-global-setup.js +19 -0
  66. package/testing-library/types/entry.d.ts +1 -0
  67. package/transform/dist/wasm.cjs +1 -1
  68. package/worklet-runtime/dist/dev.js +18 -10
  69. package/worklet-runtime/dist/main.js +1 -1
  70. package/worklet-runtime/lib/bindings/bindings.d.ts +1 -1
  71. package/worklet-runtime/lib/bindings/bindings.js +9 -1
  72. package/worklet-runtime/lib/bindings/bindings.js.map +1 -1
  73. package/worklet-runtime/lib/global.d.ts +1 -0
  74. package/worklet-runtime/lib/listeners.js +2 -8
  75. package/worklet-runtime/lib/listeners.js.map +1 -1
  76. package/worklet-runtime/lib/runOnMainThread.d.ts +2 -0
  77. package/worklet-runtime/lib/runOnMainThread.js +21 -0
  78. package/worklet-runtime/lib/runOnMainThread.js.map +1 -0
  79. package/worklet-runtime/lib/workletRuntime.js +2 -0
  80. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
  81. package/runtime/lib/worklet/execMap.js.map +0 -1
  82. package/runtime/lib/worklet/functionCall.js.map +0 -1
  83. package/runtime/lib/worklet/runOnBackground.js.map +0 -1
  84. package/runtime/lib/worklet/runOnMainThread.js.map +0 -1
  85. package/runtime/lib/worklet/transformToWorklet.js.map +0 -1
  86. package/runtime/lib/worklet/workletRef.js.map +0 -1
  87. package/runtime/lib/worklet/workletRefPool.d.ts +0 -1
  88. package/runtime/lib/worklet/workletRefPool.js.map +0 -1
  89. /package/runtime/lib/worklet/{execMap.d.ts → call/execMap.d.ts} +0 -0
  90. /package/runtime/lib/worklet/{functionCall.d.ts → call/functionCall.d.ts} +0 -0
  91. /package/runtime/lib/worklet/{runOnBackground.d.ts → call/runOnBackground.d.ts} +0 -0
  92. /package/runtime/lib/worklet/{runOnMainThread.d.ts → call/runOnMainThread.d.ts} +0 -0
  93. /package/runtime/lib/worklet/{transformToWorklet.d.ts → call/transformToWorklet.d.ts} +0 -0
  94. /package/runtime/lib/worklet/{transformToWorklet.js → call/transformToWorklet.js} +0 -0
  95. /package/runtime/lib/worklet/{workletRef.d.ts → ref/workletRef.d.ts} +0 -0
@@ -14580,17 +14580,19 @@ function waitSchedule() {
14580
14580
  return result;
14581
14581
  }
14582
14582
  });
14583
- function pure_render(ui, { queries, wrapper: WrapperComponent, enableMainThread = false, enableBackgroundThread = true } = {}) {
14583
+ function pure_render(ui, { queries, wrapper: WrapperComponent, enableMainThread = false, enableBackgroundThread = true, isRerender = false } = {}) {
14584
14584
  if (!enableMainThread && !enableBackgroundThread) throw new Error('You must enable at least one thread for rendering (enableMainThread or enableBackgroundThread)');
14585
14585
  const wrapUiIfNeeded = (innerElement)=>WrapperComponent ? h(WrapperComponent, null, innerElement) : innerElement;
14586
14586
  const comp = wrapUiIfNeeded(ui);
14587
14587
  const compMainThread = cloneElement(comp);
14588
14588
  const compBackgroundThread = cloneElement(comp);
14589
- globalThis.lynxTestingEnv.switchToMainThread();
14590
- __root.__jsx = enableMainThread ? compMainThread : null;
14591
- act(()=>{
14592
- renderPage();
14593
- });
14589
+ if (!isRerender) {
14590
+ globalThis.lynxTestingEnv.switchToMainThread();
14591
+ __root.__jsx = enableMainThread ? compMainThread : null;
14592
+ act(()=>{
14593
+ renderPage();
14594
+ });
14595
+ }
14594
14596
  if (enableBackgroundThread) {
14595
14597
  globalThis.lynxTestingEnv.switchToBackgroundThread();
14596
14598
  act(()=>{
@@ -14602,14 +14604,24 @@ function pure_render(ui, { queries, wrapper: WrapperComponent, enableMainThread
14602
14604
  container: lynxTestingEnv.mainThread.elementTree.root,
14603
14605
  unmount: cleanup,
14604
14606
  rerender: (rerenderUi)=>{
14605
- lynxTestingEnv.reset();
14606
- return pure_render(wrapUiIfNeeded(rerenderUi), {
14607
+ pure_render(rerenderUi, {
14607
14608
  queries,
14608
14609
  wrapper: WrapperComponent,
14609
14610
  enableMainThread,
14610
- enableBackgroundThread
14611
+ enableBackgroundThread,
14612
+ isRerender: true
14611
14613
  });
14612
14614
  },
14615
+ asFragment: ()=>{
14616
+ const { document: document1 } = lynxTestingEnv.jsdom.window;
14617
+ const container = lynxTestingEnv.mainThread.elementTree.root;
14618
+ if ('function' == typeof document1.createRange) return document1.createRange().createContextualFragment(container.innerHTML);
14619
+ {
14620
+ const template = document1.createElement('template');
14621
+ template.innerHTML = container.innerHTML;
14622
+ return template.content;
14623
+ }
14624
+ },
14613
14625
  ...(0, dom_esm.E5)(lynxTestingEnv.mainThread.elementTree.root, queries)
14614
14626
  };
14615
14627
  }
@@ -1,8 +1,10 @@
1
1
  import { options } from "preact";
2
+ import { expect } from "vitest";
2
3
  import { BackgroundSnapshotInstance } from "../../runtime/lib/backgroundSnapshot.js";
3
4
  import { clearCommitTaskId, replaceCommitHook } from "../../runtime/lib/lifecycle/patch/commit.js";
4
5
  import { deinitGlobalSnapshotPatch } from "../../runtime/lib/lifecycle/patch/snapshotPatch.js";
5
6
  import { injectUpdateMainThread } from "../../runtime/lib/lifecycle/patch/updateMainThread.js";
7
+ import { injectUpdateMTRefInitValue } from "../../runtime/lib/worklet/ref/updateInitValue.js";
6
8
  import { injectCalledByNative } from "../../runtime/lib/lynx/calledByNative.js";
7
9
  import { flushDelayedLifecycleEvents, injectTt } from "../../runtime/lib/lynx/tt.js";
8
10
  import { setRoot } from "../../runtime/lib/root.js";
@@ -11,9 +13,26 @@ import { destroyWorklet } from "../../runtime/lib/worklet/destroy.js";
11
13
  import { initApiEnv } from "../../worklet-runtime/lib/api/lynxApi.js";
12
14
  import { initEventListeners } from "../../worklet-runtime/lib/listeners.js";
13
15
  import { initWorklet } from "../../worklet-runtime/lib/workletRuntime.js";
16
+ expect.addSnapshotSerializer({
17
+ test (val) {
18
+ return Boolean(val && 'object' == typeof val && Array.isArray(val.refAttr) && Object.prototype.hasOwnProperty.call(val, 'task') && 'function' == typeof val.exec);
19
+ },
20
+ print (val, serialize) {
21
+ const printed = serialize({
22
+ refAttr: Array.isArray(val.refAttr) ? [
23
+ ...val.refAttr
24
+ ] : val.refAttr,
25
+ task: val.task
26
+ });
27
+ if (printed.startsWith('Object')) return printed.replace(/^Object/, 'RefProxy');
28
+ if (printed.startsWith('{')) return `RefProxy ${printed}`;
29
+ return printed;
30
+ }
31
+ });
14
32
  const { onInjectMainThreadGlobals, onInjectBackgroundThreadGlobals, onResetLynxTestingEnv, onSwitchedToMainThread, onSwitchedToBackgroundThread, onInitWorkletRuntime } = globalThis;
15
33
  injectCalledByNative();
16
34
  injectUpdateMainThread();
35
+ injectUpdateMTRefInitValue();
17
36
  replaceCommitHook();
18
37
  globalThis.onInitWorkletRuntime = ()=>{
19
38
  if (onInitWorkletRuntime) onInitWorkletRuntime();
@@ -143,6 +143,7 @@ export type RenderResult<Q extends Queries = typeof queries> = {
143
143
  container: LynxElement;
144
144
  rerender: (ui: React.ReactNode) => void;
145
145
  unmount: () => boolean;
146
+ asFragment: () => DocumentFragment;
146
147
  } & { [P in keyof Q]: BoundFunction<Q[P]> };
147
148
 
148
149
  /**