@lynx-js/react 0.110.0 → 0.110.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 (112) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/components/lib/Page.js.map +1 -1
  3. package/components/src/Page.ts +1 -1
  4. package/package.json +1 -1
  5. package/refresh/.turbo/turbo-build.log +1 -1
  6. package/runtime/lib/backgroundSnapshot.js +2 -1
  7. package/runtime/lib/backgroundSnapshot.js.map +1 -1
  8. package/runtime/lib/compat/initData.d.ts +7 -5
  9. package/runtime/lib/compat/initData.js +1 -2
  10. package/runtime/lib/compat/initData.js.map +1 -1
  11. package/runtime/lib/compat/lynxComponent.js +10 -12
  12. package/runtime/lib/compat/lynxComponent.js.map +1 -1
  13. package/runtime/lib/debug/profile.js +1 -0
  14. package/runtime/lib/debug/profile.js.map +1 -1
  15. package/runtime/lib/gesture/processGestureBagkround.d.ts +1 -1
  16. package/runtime/lib/gesture/processGestureBagkround.js +4 -1
  17. package/runtime/lib/gesture/processGestureBagkround.js.map +1 -1
  18. package/runtime/lib/gesture/types.js.map +1 -1
  19. package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +1 -1
  20. package/runtime/lib/hydrate.d.ts +1 -1
  21. package/runtime/lib/hydrate.js +5 -4
  22. package/runtime/lib/hydrate.js.map +1 -1
  23. package/runtime/lib/internal.d.ts +3 -2
  24. package/runtime/lib/internal.js +3 -2
  25. package/runtime/lib/internal.js.map +1 -1
  26. package/runtime/lib/legacy-react-runtime/index.js +1 -1
  27. package/runtime/lib/legacy-react-runtime/index.js.map +1 -1
  28. package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  29. package/runtime/lib/lifecycle/patch/updateMainThread.js +4 -4
  30. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  31. package/runtime/lib/lifecycle/reload.js +1 -1
  32. package/runtime/lib/lifecycle/reload.js.map +1 -1
  33. package/runtime/lib/list.d.ts +2 -46
  34. package/runtime/lib/list.js +23 -200
  35. package/runtime/lib/list.js.map +1 -1
  36. package/runtime/lib/listUpdateInfo.d.ts +38 -0
  37. package/runtime/lib/listUpdateInfo.js +152 -0
  38. package/runtime/lib/listUpdateInfo.js.map +1 -0
  39. package/runtime/lib/lynx/calledByNative.js +2 -2
  40. package/runtime/lib/lynx/calledByNative.js.map +1 -1
  41. package/runtime/lib/lynx-api.js +3 -0
  42. package/runtime/lib/lynx-api.js.map +1 -1
  43. package/runtime/lib/lynx.js +1 -0
  44. package/runtime/lib/lynx.js.map +1 -1
  45. package/runtime/lib/opcodes.js +2 -1
  46. package/runtime/lib/opcodes.js.map +1 -1
  47. package/runtime/lib/pendingListUpdates.d.ts +6 -0
  48. package/runtime/lib/pendingListUpdates.js +16 -0
  49. package/runtime/lib/pendingListUpdates.js.map +1 -0
  50. package/runtime/lib/renderToOpcodes/index.js +7 -7
  51. package/runtime/lib/renderToOpcodes/index.js.map +1 -1
  52. package/runtime/lib/snapshot/dynamicPartType.d.ts +12 -0
  53. package/runtime/lib/snapshot/dynamicPartType.js +17 -0
  54. package/runtime/lib/snapshot/dynamicPartType.js.map +1 -0
  55. package/runtime/lib/snapshot/gesture.js +3 -0
  56. package/runtime/lib/snapshot/gesture.js.map +1 -1
  57. package/runtime/lib/snapshot/list.d.ts +3 -0
  58. package/runtime/lib/snapshot/list.js +23 -0
  59. package/runtime/lib/snapshot/list.js.map +1 -0
  60. package/runtime/lib/snapshot/platformInfo.d.ts +10 -0
  61. package/runtime/lib/snapshot/platformInfo.js +6 -3
  62. package/runtime/lib/snapshot/platformInfo.js.map +1 -1
  63. package/runtime/lib/snapshot/ref.d.ts +3 -0
  64. package/runtime/lib/snapshot/ref.js.map +1 -1
  65. package/runtime/lib/snapshot/spread.d.ts +2 -2
  66. package/runtime/lib/snapshot/spread.js +4 -5
  67. package/runtime/lib/snapshot/spread.js.map +1 -1
  68. package/runtime/lib/snapshot/workletEvent.js +1 -1
  69. package/runtime/lib/snapshot/workletEvent.js.map +1 -1
  70. package/runtime/lib/snapshot/workletRef.d.ts +1 -1
  71. package/runtime/lib/snapshot/workletRef.js.map +1 -1
  72. package/runtime/lib/snapshot.d.ts +5 -14
  73. package/runtime/lib/snapshot.js +18 -27
  74. package/runtime/lib/snapshot.js.map +1 -1
  75. package/runtime/lib/snapshotInstanceHydrationMap.js.map +1 -1
  76. package/runtime/lib/utils.js +1 -1
  77. package/runtime/lib/utils.js.map +1 -1
  78. package/runtime/src/backgroundSnapshot.ts +4 -8
  79. package/runtime/src/compat/initData.ts +10 -9
  80. package/runtime/src/compat/lynxComponent.ts +12 -13
  81. package/runtime/src/debug/profile.ts +1 -0
  82. package/runtime/src/gesture/processGestureBagkround.ts +5 -1
  83. package/runtime/src/gesture/types.ts +3 -0
  84. package/runtime/src/hooks/useLynxGlobalEventListener.ts +1 -1
  85. package/runtime/src/hydrate.ts +6 -4
  86. package/runtime/src/internal.ts +3 -2
  87. package/runtime/src/legacy-react-runtime/index.ts +1 -1
  88. package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +1 -1
  89. package/runtime/src/lifecycle/patch/updateMainThread.ts +5 -5
  90. package/runtime/src/lifecycle/reload.ts +1 -1
  91. package/runtime/src/list.ts +26 -264
  92. package/runtime/src/listUpdateInfo.ts +221 -0
  93. package/runtime/src/lynx/calledByNative.ts +2 -2
  94. package/runtime/src/lynx-api.ts +4 -1
  95. package/runtime/src/lynx.ts +1 -0
  96. package/runtime/src/opcodes.ts +2 -1
  97. package/runtime/src/pendingListUpdates.ts +18 -0
  98. package/runtime/src/renderToOpcodes/index.ts +7 -7
  99. package/runtime/src/snapshot/dynamicPartType.ts +16 -0
  100. package/runtime/src/snapshot/gesture.ts +3 -0
  101. package/runtime/src/snapshot/list.ts +36 -0
  102. package/runtime/src/snapshot/platformInfo.ts +19 -5
  103. package/runtime/src/snapshot/ref.ts +1 -0
  104. package/runtime/src/snapshot/spread.ts +42 -17
  105. package/runtime/src/snapshot/workletEvent.ts +1 -1
  106. package/runtime/src/snapshot/workletRef.ts +1 -1
  107. package/runtime/src/snapshot.ts +23 -31
  108. package/runtime/src/snapshotInstanceHydrationMap.ts +1 -1
  109. package/runtime/src/utils.ts +3 -3
  110. package/testing-library/dist/env/vitest.js +3 -3
  111. package/testing-library/dist/vitest.config.js +7 -7
  112. package/transform/cjs/main.cjs +4 -0
@@ -18,23 +18,14 @@ import type { Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bin
18
18
 
19
19
  import type { BackgroundSnapshotInstance } from './backgroundSnapshot.js';
20
20
  import { SnapshotOperation, __globalSnapshotPatch } from './lifecycle/patch/snapshotPatch.js';
21
- import { ListUpdateInfoRecording, __pendingListUpdates, snapshotDestroyList } from './list.js';
21
+ import { ListUpdateInfoRecording } from './listUpdateInfo.js';
22
+ import { __pendingListUpdates } from './pendingListUpdates.js';
23
+ import { DynamicPartType } from './snapshot/dynamicPartType.js';
24
+ import { snapshotDestroyList } from './snapshot/list.js';
25
+ import type { PlatformInfo } from './snapshot/platformInfo.js';
22
26
  import { unref } from './snapshot/ref.js';
23
27
  import { isDirectOrDeepEqual } from './utils.js';
24
28
 
25
- /**
26
- * Types of dynamic parts that can be updated in a snapshot
27
- * These are determined at compile time through static analysis
28
- */
29
- export const enum DynamicPartType {
30
- Attr = 0, // Regular attribute updates
31
- Spread, // Spread operator in JSX
32
- Slot, // Slot for component children
33
- Children, // Regular children updates
34
- ListChildren, // List/array children updates
35
- MultiChildren, // Multiple children updates (compat layer)
36
- }
37
-
38
29
  /**
39
30
  * A snapshot definition that contains all the information needed to create and update elements
40
31
  * This is generated at compile time through static analysis of the JSX
@@ -175,7 +166,7 @@ export const backgroundSnapshotInstanceManager: {
175
166
  }
176
167
  const spreadKey = res[2];
177
168
  if (spreadKey) {
178
- return ctx.__values![expIndex][spreadKey];
169
+ return (ctx.__values![expIndex] as { [spreadKey]: unknown })[spreadKey];
179
170
  } else {
180
171
  return ctx.__values![expIndex];
181
172
  }
@@ -268,10 +259,10 @@ export class SnapshotInstance {
268
259
  __snapshot_def: Snapshot;
269
260
  __elements?: FiberElement[] | undefined;
270
261
  __element_root?: FiberElement | undefined;
271
- __values?: any[] | undefined;
262
+ __values?: unknown[] | undefined;
272
263
  __current_slot_index = 0;
273
264
  __worklet_ref_set?: Set<WorkletRefImpl<any> | Worklet>;
274
- __listItemPlatformInfo?: any;
265
+ __listItemPlatformInfo?: PlatformInfo;
275
266
 
276
267
  constructor(public type: string, id?: number) {
277
268
  this.__snapshot_def = snapshotManager.values.get(type)!;
@@ -280,7 +271,7 @@ export class SnapshotInstance {
280
271
  throw new Error('Snapshot not found: ' + type);
281
272
  }
282
273
 
283
- id ||= snapshotInstanceManager.nextId -= 1;
274
+ id ??= snapshotInstanceManager.nextId -= 1;
284
275
  this.__id = id;
285
276
  snapshotInstanceManager.values.set(id, this);
286
277
  }
@@ -589,23 +580,17 @@ export class SnapshotInstance {
589
580
  }
590
581
 
591
582
  setAttribute(key: string | number, value: any): void {
592
- const helper = (index: number, oldValue: any, newValue: any) => {
593
- if (isDirectOrDeepEqual(oldValue, newValue)) {}
594
- else {
595
- this.__snapshot_def.update![index]!(this, index, oldValue);
596
- }
597
- };
598
-
599
583
  if (key === 'values') {
600
584
  const oldValues = this.__values;
601
- this.__values = value;
585
+ const values = value as unknown[];
586
+ this.__values = values;
602
587
  if (oldValues) {
603
- for (let index = 0; index < value.length; index++) {
604
- helper(index, oldValues[index], value[index]);
588
+ for (let index = 0; index < values.length; index++) {
589
+ this.callUpdateIfNotDirectOrDeepEqual(index, oldValues[index], values[index]);
605
590
  }
606
591
  } else {
607
- for (let index = 0; index < value.length; index++) {
608
- helper(index, undefined, value[index]);
592
+ for (let index = 0; index < values.length; index++) {
593
+ this.callUpdateIfNotDirectOrDeepEqual(index, undefined, values[index]);
609
594
  }
610
595
  }
611
596
  return;
@@ -613,7 +598,7 @@ export class SnapshotInstance {
613
598
 
614
599
  const index = typeof key === 'string' ? Number(key.slice(2)) : key;
615
600
  this.__values ??= [];
616
- helper(index, this.__values[index], this.__values[index] = value);
601
+ this.callUpdateIfNotDirectOrDeepEqual(index, this.__values[index], this.__values[index] = value);
617
602
  }
618
603
 
619
604
  toJSON(): Omit<SerializedSnapshotInstance, 'children'> & { children: SnapshotInstance[] | undefined } {
@@ -624,4 +609,11 @@ export class SnapshotInstance {
624
609
  children: this.__firstChild ? this.childNodes : undefined,
625
610
  };
626
611
  }
612
+
613
+ callUpdateIfNotDirectOrDeepEqual(index: number, oldValue: any, newValue: any): void {
614
+ if (isDirectOrDeepEqual(oldValue, newValue)) {}
615
+ else {
616
+ this.__snapshot_def.update![index]!(this, index, oldValue);
617
+ }
618
+ }
627
619
  }
@@ -9,7 +9,7 @@
9
9
  * The map is used by the ref system to translate between snapshot instance IDs when
10
10
  * operations need to cross the thread boundary during the commit phase.
11
11
  */
12
- const hydrationMap: Map<number, number> = new Map();
12
+ const hydrationMap: Map<number, number> = new Map<number, number>();
13
13
 
14
14
  /**
15
15
  * @internal
@@ -14,7 +14,7 @@ export function isDirectOrDeepEqual(a: any, b: any): boolean {
14
14
  }
15
15
 
16
16
  export function isEmptyObject(obj?: object): obj is Record<string, never> {
17
- for (var _ in obj) return false;
17
+ for (const _ in obj) return false;
18
18
  return true;
19
19
  }
20
20
 
@@ -25,11 +25,11 @@ export function isSdkVersionGt(major: number, minor: number): boolean {
25
25
  }
26
26
 
27
27
  export function pick<T extends object, K extends keyof T>(obj: T, keys: Iterable<K>): Pick<T, K> {
28
- const result: any = {};
28
+ const result: Partial<Pick<T, K>> = {};
29
29
  for (const key of keys) {
30
30
  if (key in obj) {
31
31
  result[key] = obj[key];
32
32
  }
33
33
  }
34
- return result;
34
+ return result as Pick<T, K>;
35
35
  }
@@ -1,5 +1,5 @@
1
1
  import { builtinEnvironments } from "vitest/environments";
2
- import external_events_default from "events";
2
+ import events from "events";
3
3
  function util_define(object, properties) {
4
4
  for (const name of Object.getOwnPropertyNames(properties)){
5
5
  const propDesc = Object.getOwnPropertyDescriptor(properties, name);
@@ -321,7 +321,7 @@ function createPolyfills() {
321
321
  ]);
322
322
  }
323
323
  };
324
- const ee = new external_events_default();
324
+ const ee = new events();
325
325
  ee.dispatchEvent = ({ type, data })=>{
326
326
  const isMainThread = __MAIN_THREAD__;
327
327
  lynxTestingEnv.switchToBackgroundThread();
@@ -428,7 +428,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
428
428
  updateData: {}
429
429
  }
430
430
  };
431
- const globalEventEmitter = new external_events_default();
431
+ const globalEventEmitter = new events();
432
432
  globalEventEmitter.trigger = globalEventEmitter.emit;
433
433
  globalEventEmitter.toggle = globalEventEmitter.emit;
434
434
  target.lynx = {
@@ -1,10 +1,10 @@
1
1
  import { defineConfig } from "vitest/config";
2
2
  import { VitestPackageInstaller } from "vitest/node";
3
- import external_path_default from "path";
3
+ import path from "path";
4
4
  import { fileURLToPath } from "url";
5
5
  import { createRequire } from "module";
6
6
  const vitest_config_filename = fileURLToPath(import.meta.url);
7
- const vitest_config_dirname = external_path_default.dirname(vitest_config_filename);
7
+ const vitest_config_dirname = path.dirname(vitest_config_filename);
8
8
  const vitest_config_require = createRequire(import.meta.url);
9
9
  async function ensurePackagesInstalled() {
10
10
  const installer = new VitestPackageInstaller();
@@ -28,8 +28,8 @@ const createVitestConfig = async (options)=>{
28
28
  return '';
29
29
  }
30
30
  const { transformReactLynxSync } = vitest_config_require('@lynx-js/react/transform');
31
- const relativePath = normalizeSlashes(external_path_default.relative(vitest_config_dirname, sourcePath));
32
- const basename = external_path_default.basename(sourcePath);
31
+ const relativePath = normalizeSlashes(path.relative(vitest_config_dirname, sourcePath));
32
+ const basename = path.basename(sourcePath);
33
33
  const result = transformReactLynxSync(sourceText, {
34
34
  mode: 'test',
35
35
  pluginName: '',
@@ -71,7 +71,7 @@ const createVitestConfig = async (options)=>{
71
71
  server: {
72
72
  fs: {
73
73
  allow: [
74
- external_path_default.join(vitest_config_dirname, '..')
74
+ path.join(vitest_config_dirname, '..')
75
75
  ]
76
76
  }
77
77
  },
@@ -82,12 +82,12 @@ const createVitestConfig = async (options)=>{
82
82
  environment: vitest_config_require.resolve('./env/vitest'),
83
83
  globals: true,
84
84
  setupFiles: [
85
- external_path_default.join(vitest_config_dirname, 'vitest-global-setup')
85
+ path.join(vitest_config_dirname, 'vitest-global-setup')
86
86
  ]
87
87
  }
88
88
  });
89
89
  };
90
90
  function normalizeSlashes(file) {
91
- return file.replaceAll(external_path_default.win32.sep, '/');
91
+ return file.replaceAll(path.win32.sep, '/');
92
92
  }
93
93
  export { createVitestConfig };
@@ -1,6 +1,10 @@
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
+
5
+ /* eslint-disable n/no-unpublished-require */
6
+
4
7
  const { default: _exports } = require('../dist/wasm.cjs');
5
8
 
9
+ // eslint-disable-next-line n/no-missing-require
6
10
  module.exports = process.env['USE_NAPI'] ? require('../index.cjs') : _exports;