@lynx-js/react 0.129.1 → 0.129.2

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 (121) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +1 -1
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/globalProps.test.ts +27 -6
  6. package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
  7. package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -0
  8. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
  9. package/runtime/__test__/element-template/native/mts-destroy.test.ts +8 -3
  10. package/runtime/__test__/element-template/native/reload.test.ts +87 -0
  11. package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
  12. package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
  13. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
  14. package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
  15. package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
  16. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +15 -0
  17. package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
  18. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
  19. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
  20. package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
  21. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -1
  22. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +188 -0
  23. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +2 -2
  24. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
  25. package/runtime/__test__/snapshot/ref.test.jsx +30 -0
  26. package/runtime/lazy/element-template-internal.js +1 -0
  27. package/runtime/lib/core/globalProps.js +1 -1
  28. package/runtime/lib/core/globalProps.js.map +1 -1
  29. package/runtime/lib/element-template/background/attr-slots.js +5 -2
  30. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  31. package/runtime/lib/element-template/background/destroy.js +16 -11
  32. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  33. package/runtime/lib/element-template/background/hydrate.js +23 -0
  34. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  35. package/runtime/lib/element-template/debug/alog.d.ts +1 -1
  36. package/runtime/lib/element-template/debug/alog.js +4 -1
  37. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  38. package/runtime/lib/element-template/internal.d.ts +1 -1
  39. package/runtime/lib/element-template/internal.js +1 -1
  40. package/runtime/lib/element-template/internal.js.map +1 -1
  41. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +6 -1
  42. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  43. package/runtime/lib/element-template/native/patch-listener.js +1 -1
  44. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  45. package/runtime/lib/element-template/native/reload-background.js +1 -1
  46. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  47. package/runtime/lib/element-template/native/reload-main-thread.js +33 -9
  48. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  49. package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
  50. package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
  51. package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
  52. package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
  53. package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
  54. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  55. package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
  56. package/runtime/lib/element-template/protocol/opcodes.js +1 -0
  57. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  58. package/runtime/lib/element-template/protocol/types.d.ts +7 -1
  59. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  60. package/runtime/lib/element-template/runtime/patch.js +27 -2
  61. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  62. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +4 -2
  63. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
  64. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  65. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -2
  66. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +368 -58
  67. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  68. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +2 -1
  69. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
  70. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  71. package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
  72. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  73. package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
  74. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  75. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +5 -0
  76. package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
  77. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  78. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  79. package/runtime/src/core/globalProps.ts +1 -1
  80. package/runtime/src/element-template/background/attr-slots.ts +5 -1
  81. package/runtime/src/element-template/background/destroy.ts +16 -13
  82. package/runtime/src/element-template/background/hydrate.ts +23 -0
  83. package/runtime/src/element-template/debug/alog.ts +5 -2
  84. package/runtime/src/element-template/internal.ts +1 -0
  85. package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
  86. package/runtime/src/element-template/native/patch-listener.ts +1 -1
  87. package/runtime/src/element-template/native/reload-background.ts +1 -1
  88. package/runtime/src/element-template/native/reload-main-thread.ts +30 -10
  89. package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
  90. package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
  91. package/runtime/src/element-template/protocol/opcodes.ts +1 -0
  92. package/runtime/src/element-template/protocol/types.ts +8 -0
  93. package/runtime/src/element-template/runtime/patch.ts +33 -0
  94. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
  95. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +441 -65
  96. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +12 -2
  97. package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
  98. package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
  99. package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
  100. package/runtime/types/types.d.ts +2 -1
  101. package/testing-library/.turbo/turbo-build.log +7 -7
  102. package/transform/.turbo/turbo-build$colon$wasm.log +205 -91
  103. package/transform/__test__/fixture.spec.js +11 -11
  104. package/transform/__test__/main-thread-object-compat.spec.js +111 -0
  105. package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
  106. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
  107. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +7 -9
  108. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
  109. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
  110. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +7 -7
  111. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -7
  112. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +8 -8
  113. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +8 -8
  114. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
  115. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
  116. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
  117. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
  118. package/transform/dist/wasm.cjs +1 -1
  119. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +160 -133
  120. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  121. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +180 -293
@@ -6,8 +6,9 @@ export interface MTRefNativeWrapper {
6
6
  value: MTRefValue;
7
7
  }
8
8
  export declare function isMTRefValue(value: unknown): value is MTRefValue;
9
+ export declare function isMTRefNativeWrapper(value: unknown): value is MTRefNativeWrapper;
9
10
  export declare function retainMTRefValue(value: MTRefValue): void;
10
- export declare function hydrateMTRefValue(value: MTRefValue, previousValue: MTRefValue | undefined): void;
11
+ export declare function hydrateMTRefValue(value: MTRefValue, previousValue: MTRefValue | null | undefined): void;
11
12
  export declare function attachMTRefValue(value: MTRefValue, nativeRef: ElementRef): void;
12
13
  export declare function cleanupMTRefValue(value: MTRefValue): void;
13
14
  export declare function prepareMTRefForNative(rawValue: unknown, previousPreparedValue?: unknown, previousRawValue?: unknown): SerializableValue | null;
@@ -8,6 +8,13 @@ import { isMainThreadRef } from '../../../core/main-thread-ref.js';
8
8
  export function isMTRefValue(value) {
9
9
  return isMainThreadRef(value) || isMainThreadFunction(value);
10
10
  }
11
+ export function isMTRefNativeWrapper(value) {
12
+ return value !== null
13
+ && typeof value === 'object'
14
+ && !Array.isArray(value)
15
+ && value.type === 'main-thread-ref'
16
+ && isMTRefValue(value.value);
17
+ }
11
18
  export function retainMTRefValue(value) {
12
19
  if (isMainThreadFunction(value)) {
13
20
  retainMainThreadBackgroundFunctionCtx(value);
@@ -31,7 +38,9 @@ export function cleanupMTRefValue(value) {
31
38
  return;
32
39
  }
33
40
  if (typeof value._unmount === 'function') {
34
- value._unmount();
41
+ const unmount = value._unmount;
42
+ delete value._unmount;
43
+ unmount();
35
44
  return;
36
45
  }
37
46
  runWorkletCtx(value, [null]);
@@ -1 +1 @@
1
- {"version":3,"file":"main-thread-ref-ctx.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-ref-ctx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG7G,OAAO,EACL,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAUnE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IAChD,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,qCAAqC,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAiB,EACjB,aAAqC;IAErC,IAAI,oBAAoB,CAAC,KAAK,CAAC,IAAI,aAAa,IAAI,oBAAoB,CAAC,aAAa,CAAC,EAAE,CAAC;QACxF,iBAAiB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC1C,C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ACN,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,KAAK;KAC0B,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 { hydrateWorkletCtx, runWorkletCtx, updateWorkletRef } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport {\n registerMainThreadBackgroundFunctionCtx,\n retainMainThreadBackgroundFunctionCtx,\n} from './main-thread-background-function.js';\nimport { isMainThreadFunction } from '../../../core/main-thread-function.js';\nimport { isMainThreadRef } from '../../../core/main-thread-ref.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\nexport type MTRefValue = WorkletRefImpl<Element> | Worklet;\n\nexport interface MTRefNativeWrapper {\n type: 'main-thread-ref';\n value: MTRefValue;\n}\n\nexport function isMTRefValue(value: unknown): value is MTRefValue {\n return isMainThreadRef(value) || isMainThreadFunction(value);\n}\n\nexport function retainMTRefValue(value: MTRefValue): void {\n if (isMainThreadFunction(value)) {\n retainMainThreadBackgroundFunctionCtx(value);\n }\n}\n\nexport function hydrateMTRefValue(\n value: MTRefValue,\n previousValue: MTRefValue | undefined,\n): void {\n if (isMainThreadFunction(value) && previousValue && isMainThreadFunction(previousValue)) {\n hydrateWorkletCtx(value, previousValue);\n }\n}\n\nexport function attachMTRefValue(\n value: MTRefValue,\n nativeRef: ElementRef,\n): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, nativeRef);\n return;\n }\n value._unmount = runWorkletCtx(\n value,\n [{ elementRefptr: nativeRef }] as unknown as Parameters<typeof runWorkletCtx>[1],\n ) as () => void;\n}\n\nexport function cleanupMTRefValue(value: MTRefValue): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, null);\n return;\n }\n if (typeof value._unmount === 'function') {\n value._unmount();\n return;\n }\n runWorkletCtx(value, [null]);\n}\n\nexport function prepareMTRefForNative(\n rawValue: unknown,\n previousPreparedValue?: unknown,\n previousRawValue?: unknown,\n): SerializableValue | null {\n if (rawValue === null || rawValue === undefined) {\n return null;\n }\n if (!isMTRefValue(rawValue)) {\n throw new Error('ElementTemplate main-thread:ref expects a MainThreadRef object or a main-thread function.');\n }\n if (previousRawValue === rawValue) {\n return previousPreparedValue as SerializableValue;\n }\n\n let value: MTRefValue;\n if (isMainThreadFunction(rawValue)) {\n value = { ...rawValue };\n registerMainThreadBackgroundFunctionCtx(value);\n } else {\n value = rawValue;\n }\n\n return {\n type: 'main-thread-ref',\n value,\n } as unknown as SerializableValue;\n}\n"]}
1
+ {"version":3,"file":"main-thread-ref-ctx.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-ref-ctx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG7G,OAAO,EACL,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAUnE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,KAAK,IAAI;WAChB,OAAO,KAAK,KAAK,QAAQ;WACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;WACpB,KAA4B,CAAC,IAAI,KAAK,iBAAiB;WACxD,YAAY,CAAE,KAA6B,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,U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,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,2FAA2F,CAAC,CAAC;IAC/G,CAAC;IACD,IAAI,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,qBAA0C,CAAC;IACpD,CAAC;IAED,IAAI,KAAiB,CAAC;IACtB,IAAI,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnC,KAAK,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QACxB,uCAAuC,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,KAAK;KAC0B,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 { hydrateWorkletCtx, runWorkletCtx, updateWorkletRef } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport {\n registerMainThreadBackgroundFunctionCtx,\n retainMainThreadBackgroundFunctionCtx,\n} from './main-thread-background-function.js';\nimport { isMainThreadFunction } from '../../../core/main-thread-function.js';\nimport { isMainThreadRef } from '../../../core/main-thread-ref.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\nexport type MTRefValue = WorkletRefImpl<Element> | Worklet;\n\nexport interface MTRefNativeWrapper {\n type: 'main-thread-ref';\n value: MTRefValue;\n}\n\nexport function isMTRefValue(value: unknown): value is MTRefValue {\n return isMainThreadRef(value) || isMainThreadFunction(value);\n}\n\nexport function isMTRefNativeWrapper(value: unknown): value is MTRefNativeWrapper {\n return value !== null\n && typeof value === 'object'\n && !Array.isArray(value)\n && (value as { type?: unknown }).type === 'main-thread-ref'\n && isMTRefValue((value as { value?: unknown }).value);\n}\n\nexport function retainMTRefValue(value: MTRefValue): void {\n if (isMainThreadFunction(value)) {\n retainMainThreadBackgroundFunctionCtx(value);\n }\n}\n\nexport function hydrateMTRefValue(\n value: MTRefValue,\n previousValue: MTRefValue | null | undefined,\n): void {\n if (isMainThreadFunction(value) && previousValue && isMainThreadFunction(previousValue)) {\n hydrateWorkletCtx(value, previousValue);\n }\n}\n\nexport function attachMTRefValue(\n value: MTRefValue,\n nativeRef: ElementRef,\n): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, nativeRef);\n return;\n }\n value._unmount = runWorkletCtx(\n value,\n [{ elementRefptr: nativeRef }] as unknown as Parameters<typeof runWorkletCtx>[1],\n ) as () => void;\n}\n\nexport function cleanupMTRefValue(value: MTRefValue): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, null);\n return;\n }\n if (typeof value._unmount === 'function') {\n const unmount = value._unmount;\n delete value._unmount;\n unmount();\n return;\n }\n runWorkletCtx(value, [null]);\n}\n\nexport function prepareMTRefForNative(\n rawValue: unknown,\n previousPreparedValue?: unknown,\n previousRawValue?: unknown,\n): SerializableValue | null {\n if (rawValue === null || rawValue === undefined) {\n return null;\n }\n if (!isMTRefValue(rawValue)) {\n throw new Error('ElementTemplate main-thread:ref expects a MainThreadRef object or a main-thread function.');\n }\n if (previousRawValue === rawValue) {\n return previousPreparedValue as SerializableValue;\n }\n\n let value: MTRefValue;\n if (isMainThreadFunction(rawValue)) {\n value = { ...rawValue };\n registerMainThreadBackgroundFunctionCtx(value);\n } else {\n value = rawValue;\n }\n\n return {\n type: 'main-thread-ref',\n value,\n } as unknown as SerializableValue;\n}\n"]}
@@ -1,13 +1,13 @@
1
1
  // Copyright 2026 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 { adaptSpreadAttrSlot } from './attr-slot-plan.js';
4
+ import { adaptTypedSpreadAttrSlot } from './attr-slot-plan.js';
5
5
  export const TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX = 0;
6
6
  export const TYPED_ELEMENT_ATTR_PLAN = [
7
7
  TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX,
8
- adaptSpreadAttrSlot,
8
+ adaptTypedSpreadAttrSlot,
9
9
  ];
10
10
  export function prepareTypedElementAttributes(handleId, attributes) {
11
- return adaptSpreadAttrSlot(handleId, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, attributes);
11
+ return adaptTypedSpreadAttrSlot(handleId, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, attributes);
12
12
  }
13
13
  //# sourceMappingURL=typed-attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typed-attributes.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/typed-attributes.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAI1D,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,uBAAuB,GAAe;IACjD,mCAAmC;IACnC,mBAAmB;CACpB,CAAC;AAEF,MAAM,UAAU,6BAA6B,CAC3C,QAAgB,EAChB,UAA4D;IAE5D,OAAO,mBAAmB,CACxB,QAAQ,EACR,mCAAmC,EACnC,UAAU,CAC6B,CAAC;AAC5C,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 { adaptSpreadAttrSlot } from './attr-slot-plan.js';\nimport type { EtAttrPlan } from './attr-slot-plan.js';\nimport type { RuntimeTypedElementAttributes, TypedElementAttributesCommand } from '../../protocol/types.js';\n\nexport const TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX = 0;\n\nexport const TYPED_ELEMENT_ATTR_PLAN: EtAttrPlan = [\n TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX,\n adaptSpreadAttrSlot,\n];\n\nexport function prepareTypedElementAttributes(\n handleId: number,\n attributes: RuntimeTypedElementAttributes | null | undefined,\n): TypedElementAttributesCommand | null {\n return adaptSpreadAttrSlot(\n handleId,\n TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX,\n attributes,\n ) as TypedElementAttributesCommand | null;\n}\n"]}
1
+ {"version":3,"file":"typed-attributes.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/typed-attributes.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAI/D,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,uBAAuB,GAAe;IACjD,mCAAmC;IACnC,wBAAwB;CACzB,CAAC;AAEF,MAAM,UAAU,6BAA6B,CAC3C,QAAgB,EAChB,UAA4D;IAE5D,OAAO,wBAAwB,CAC7B,QAAQ,EACR,mCAAmC,EACnC,UAAU,CAC6B,CAAC;AAC5C,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 { adaptTypedSpreadAttrSlot } from './attr-slot-plan.js';\nimport type { EtAttrPlan } from './attr-slot-plan.js';\nimport type { RuntimeTypedElementAttributes, TypedElementAttributesCommand } from '../../protocol/types.js';\n\nexport const TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX = 0;\n\nexport const TYPED_ELEMENT_ATTR_PLAN: EtAttrPlan = [\n TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX,\n adaptTypedSpreadAttrSlot,\n];\n\nexport function prepareTypedElementAttributes(\n handleId: number,\n attributes: RuntimeTypedElementAttributes | null | undefined,\n): TypedElementAttributesCommand | null {\n return adaptTypedSpreadAttrSlot(\n handleId,\n TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX,\n attributes,\n ) as TypedElementAttributesCommand | null;\n}\n"]}
@@ -7,6 +7,7 @@ import { delayedEvents } from './event/delayEvents.js';
7
7
  import { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';
8
8
  import { globalCommitTaskMap } from './patch/commit.js';
9
9
  import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
10
+ import { delayedUiOps } from './ref/delay.js';
10
11
  import { profileEnd, profileStart } from '../../shared/profile.js';
11
12
  import { withSyncEffectFlush } from '../../utils.js';
12
13
  import { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';
@@ -16,24 +17,29 @@ function destroyBackground() {
16
17
  profileStart('ReactLynx::destroyBackground');
17
18
  }
18
19
  deinitGlobalSnapshotPatch();
19
- withSyncEffectFlush(() => {
20
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
21
- render(null, __root);
22
- });
23
- globalCommitTaskMap.forEach(task => {
24
- task();
25
- });
26
- globalCommitTaskMap.clear();
27
- // Clear delayed events which should not be executed after destroyed.
28
- // This is important when the page is performing a reload.
29
- delayedLifecycleEvents.length = 0;
30
- if (delayedEvents) {
31
- delayedEvents.length = 0;
20
+ try {
21
+ withSyncEffectFlush(() => {
22
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
23
+ render(null, __root);
24
+ });
25
+ globalCommitTaskMap.forEach(task => {
26
+ task();
27
+ });
32
28
  }
33
- resetSnapshotBackgroundFunctionRuntime();
34
- resetSnapshotMainThreadFunctionRuntime();
35
- if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
36
- profileEnd();
29
+ finally {
30
+ globalCommitTaskMap.clear();
31
+ // Clear delayed events which should not be executed after destroyed.
32
+ // This is important when the page is performing a reload.
33
+ delayedLifecycleEvents.length = 0;
34
+ if (delayedEvents) {
35
+ delayedEvents.length = 0;
36
+ }
37
+ delayedUiOps.length = 0;
38
+ resetSnapshotBackgroundFunctionRuntime();
39
+ resetSnapshotMainThreadFunctionRuntime();
40
+ if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
41
+ profileEnd();
42
+ }
37
43
  }
38
44
  }
39
45
  export { destroyBackground };
@@ -1 +1 @@
1
- {"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,sCAAsC,EAAE,MAAM,oCAAoC,CAAC;AAC5F,OAAO,EAAE,sCAAsC,EAAE,MAAM,mBAAmB,CAAC;AAE3E,SAAS,iBAAiB;IACxB,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,8BAA8B,CAAC,CAAC;IAC/C,CAAC;IAED,yBAAyB,EAAE,CAAC;IAE5B,mBAAmB,CAAC,GAAG,EAAE;QACvB,iEAAiE;QACjE,MAAM,CAAC,IAAI,EAAE,MAAa,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACjC,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IACH,mBAAmB,CAAC,KAAK,EAAE,CAAC;IAC5B,qEAAqE;IACrE,0DAA0D;IAC1D,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,IAAI,aAAa,EAAE,CAAC;QAClB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;IACD,sCAAsC,EAAE,CAAC;IACzC,sCAAsC,EAAE,CAAC;IACzC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,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 { render } from 'preact';\n\nimport { __root } from '../../root.js';\nimport { delayedEvents } from './event/delayEvents.js';\nimport { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';\nimport { globalCommitTaskMap } from './patch/commit.js';\nimport { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { withSyncEffectFlush } from '../../utils.js';\nimport { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';\nimport { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';\n\nfunction destroyBackground(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::destroyBackground');\n }\n\n deinitGlobalSnapshotPatch();\n\n withSyncEffectFlush(() => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(null, __root as any);\n });\n\n globalCommitTaskMap.forEach(task => {\n task();\n });\n globalCommitTaskMap.clear();\n // Clear delayed events which should not be executed after destroyed.\n // This is important when the page is performing a reload.\n delayedLifecycleEvents.length = 0;\n if (delayedEvents) {\n delayedEvents.length = 0;\n }\n resetSnapshotBackgroundFunctionRuntime();\n resetSnapshotMainThreadFunctionRuntime();\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { destroyBackground };\n"]}
1
+ {"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,sCAAsC,EAAE,MAAM,oCAAoC,CAAC;AAC5F,OAAO,EAAE,sCAAsC,EAAE,MAAM,mBAAmB,CAAC;AAE3E,SAAS,iBAAiB;IACxB,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,8BAA8B,CAAC,CAAC;IAC/C,CAAC;IAED,yBAAyB,EAAE,CAAC;IAE5B,IAAI,CAAC;QACH,mBAAmB,CAAC,GAAG,EAAE;YACvB,iEAAiE;YACjE,MAAM,CAAC,IAAI,EAAE,MAAa,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACjC,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,mBAAmB,CAAC,KAAK,EAAE,CAAC;QAC5B,qEAAqE;QACrE,0DAA0D;QAC1D,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;QACxB,sCAAsC,EAAE,CAAC;QACzC,sCAAsC,EAAE,CAAC;QACzC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,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 { render } from 'preact';\n\nimport { __root } from '../../root.js';\nimport { delayedEvents } from './event/delayEvents.js';\nimport { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';\nimport { globalCommitTaskMap } from './patch/commit.js';\nimport { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';\nimport { delayedUiOps } from './ref/delay.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { withSyncEffectFlush } from '../../utils.js';\nimport { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';\nimport { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';\n\nfunction destroyBackground(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::destroyBackground');\n }\n\n deinitGlobalSnapshotPatch();\n\n try {\n withSyncEffectFlush(() => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(null, __root as any);\n });\n\n globalCommitTaskMap.forEach(task => {\n task();\n });\n } finally {\n globalCommitTaskMap.clear();\n // Clear delayed events which should not be executed after destroyed.\n // This is important when the page is performing a reload.\n delayedLifecycleEvents.length = 0;\n if (delayedEvents) {\n delayedEvents.length = 0;\n }\n delayedUiOps.length = 0;\n resetSnapshotBackgroundFunctionRuntime();\n resetSnapshotMainThreadFunctionRuntime();\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\nexport { destroyBackground };\n"]}
@@ -10,6 +10,11 @@ import type { RefProxyForwardedMethods } from '../../../core/ref.js';
10
10
  declare const shouldDelayUiOps: {
11
11
  value: boolean;
12
12
  };
13
+ /**
14
+ * An array of functions that will be executed later when `runDelayedUiOps` is called.
15
+ * These functions contain UI operations that need to be delayed.
16
+ */
17
+ declare const delayedUiOps: (() => void)[];
13
18
  /**
14
19
  * Executes all delayed UI operations.
15
20
  */
@@ -64,5 +64,5 @@ class RefProxy extends SelectorRefProxy {
64
64
  /**
65
65
  * @internal
66
66
  */
67
- export { RefProxy, runDelayedUiOps, shouldDelayUiOps };
67
+ export { delayedUiOps, RefProxy, runDelayedUiOps, shouldDelayUiOps };
68
68
  //# sourceMappingURL=delay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/ref/delay.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAEzC;;;GAGG;AACH,MAAM,YAAY,GAAmB,EAAE,CAAC;AAExC;;;GAGG;AACH,SAAS,UAAU,CAAC,IAAgB;IAClC,IAAI,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC3B,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,IAAI,EAAE,CAAC;IACT,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,eAAe;IACtB,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;IACnC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IACxB,gBAAgB,CAAC,KAAK,GAAG,KAAK,CAAC;IAE/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,EAAE,CAAC;IACT,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,QAAS,SAAQ,gBAA0B;IAC9B,OAAO,CAAiD;IAEzE,YAAY,OAAuD;QACjE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAES,iBAAiB;QACzB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAES,UAAU,CAAC,IAAgB;QACnC,UAAU,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,QAAQ;QACV,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACvE,OAAO,cAAc,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACvD,CAAC;CACF;AAID;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,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 { SelectorRefProxy } from '../../../core/ref.js';\nimport type { RefProxyForwardedMethods } from '../../../core/ref.js';\nimport { hydrationMap } from '../../snapshot/snapshotInstanceHydrationMap.js';\n\n/**\n * A flag to indicate whether UI operations should be delayed.\n * When set to true, UI operations will be queued in the `delayedUiOps` array\n * and executed later when `runDelayedUiOps` is called.\n * This is used before hydration to ensure UI operations are batched\n * and executed at the appropriate time.\n */\nconst shouldDelayUiOps = { value: true };\n\n/**\n * An array of functions that will be executed later when `runDelayedUiOps` is called.\n * These functions contain UI operations that need to be delayed.\n */\nconst delayedUiOps: (() => void)[] = [];\n\n/**\n * Runs a task either immediately or delays it based on the `shouldDelayUiOps` flag.\n * @param task - The function to execute.\n */\nfunction runOrDelay(task: () => void): void {\n if (shouldDelayUiOps.value) {\n delayedUiOps.push(task);\n } else {\n task();\n }\n}\n\n/**\n * Executes all delayed UI operations.\n */\nfunction runDelayedUiOps(): void {\n const tasks = delayedUiOps.slice();\n delayedUiOps.length = 0;\n shouldDelayUiOps.value = false;\n\n for (const task of tasks) {\n task();\n }\n}\n\n/**\n * A proxy class designed for managing and executing reference-based tasks.\n * It delays the execution of tasks until hydration is complete.\n */\nclass RefProxy extends SelectorRefProxy<RefProxy> {\n private readonly refAttr: [snapshotInstanceId: number, expIndex: number];\n\n constructor(refAttr: [snapshotInstanceId: number, expIndex: number]) {\n super();\n this.refAttr = refAttr;\n\n return this.createProxy();\n }\n\n protected createProxyTarget(): RefProxy {\n return new RefProxy(this.refAttr);\n }\n\n protected runOrDelay(task: () => void): void {\n runOrDelay(task);\n }\n\n get selector(): string {\n const realRefId = hydrationMap.get(this.refAttr[0]) ?? this.refAttr[0];\n return `[react-ref-${realRefId}-${this.refAttr[1]}]`;\n }\n}\n\ninterface RefProxy extends RefProxyForwardedMethods<RefProxy> {}\n\n/**\n * @internal\n */\nexport { RefProxy, runDelayedUiOps, shouldDelayUiOps };\n"]}
1
+ {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/ref/delay.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,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E,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 { SelectorRefProxy } from '../../../core/ref.js';\nimport type { RefProxyForwardedMethods } from '../../../core/ref.js';\nimport { hydrationMap } from '../../snapshot/snapshotInstanceHydrationMap.js';\n\n/**\n * A flag to indicate whether UI operations should be delayed.\n * When set to true, UI operations will be queued in the `delayedUiOps` array\n * and executed later when `runDelayedUiOps` is called.\n * This is used before hydration to ensure UI operations are batched\n * and executed at the appropriate time.\n */\nconst shouldDelayUiOps = { value: true };\n\n/**\n * An array of functions that will be executed later when `runDelayedUiOps` is called.\n * These functions contain UI operations that need to be delayed.\n */\nconst delayedUiOps: (() => void)[] = [];\n\n/**\n * Runs a task either immediately or delays it based on the `shouldDelayUiOps` flag.\n * @param task - The function to execute.\n */\nfunction runOrDelay(task: () => void): void {\n if (shouldDelayUiOps.value) {\n delayedUiOps.push(task);\n } else {\n task();\n }\n}\n\n/**\n * Executes all delayed UI operations.\n */\nfunction runDelayedUiOps(): void {\n const tasks = delayedUiOps.slice();\n delayedUiOps.length = 0;\n shouldDelayUiOps.value = false;\n\n for (const task of tasks) {\n task();\n }\n}\n\n/**\n * A proxy class designed for managing and executing reference-based tasks.\n * It delays the execution of tasks until hydration is complete.\n */\nclass RefProxy extends SelectorRefProxy<RefProxy> {\n private readonly refAttr: [snapshotInstanceId: number, expIndex: number];\n\n constructor(refAttr: [snapshotInstanceId: number, expIndex: number]) {\n super();\n this.refAttr = refAttr;\n\n return this.createProxy();\n }\n\n protected createProxyTarget(): RefProxy {\n return new RefProxy(this.refAttr);\n }\n\n protected runOrDelay(task: () => void): void {\n runOrDelay(task);\n }\n\n get selector(): string {\n const realRefId = hydrationMap.get(this.refAttr[0]) ?? this.refAttr[0];\n return `[react-ref-${realRefId}-${this.refAttr[1]}]`;\n }\n}\n\ninterface RefProxy extends RefProxyForwardedMethods<RefProxy> {}\n\n/**\n * @internal\n */\nexport { delayedUiOps, RefProxy, runDelayedUiOps, shouldDelayUiOps };\n"]}