@reckona/mreact-compat 0.0.138 → 0.0.140

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 (49) hide show
  1. package/dist/dom-props.d.ts.map +1 -1
  2. package/dist/dom-props.js +111 -44
  3. package/dist/dom-props.js.map +1 -1
  4. package/dist/element.d.ts +3 -0
  5. package/dist/element.d.ts.map +1 -1
  6. package/dist/element.js +32 -2
  7. package/dist/element.js.map +1 -1
  8. package/dist/event-listeners.d.ts +2 -4
  9. package/dist/event-listeners.d.ts.map +1 -1
  10. package/dist/event-listeners.js +2 -1
  11. package/dist/event-listeners.js.map +1 -1
  12. package/dist/fiber-child.d.ts.map +1 -1
  13. package/dist/fiber-child.js +44 -0
  14. package/dist/fiber-child.js.map +1 -1
  15. package/dist/fiber-commit.d.ts.map +1 -1
  16. package/dist/fiber-commit.js +70 -0
  17. package/dist/fiber-commit.js.map +1 -1
  18. package/dist/hooks.d.ts +4 -2
  19. package/dist/hooks.d.ts.map +1 -1
  20. package/dist/hooks.js +64 -6
  21. package/dist/hooks.js.map +1 -1
  22. package/dist/host-reconciler.d.ts.map +1 -1
  23. package/dist/host-reconciler.js +2 -2
  24. package/dist/host-reconciler.js.map +1 -1
  25. package/dist/jsx-runtime.d.ts.map +1 -1
  26. package/dist/jsx-runtime.js +2 -11
  27. package/dist/jsx-runtime.js.map +1 -1
  28. package/dist/reconciler.d.ts.map +1 -1
  29. package/dist/reconciler.js +2 -2
  30. package/dist/reconciler.js.map +1 -1
  31. package/dist/server-render.d.ts.map +1 -1
  32. package/dist/server-render.js +29 -4
  33. package/dist/server-render.js.map +1 -1
  34. package/dist/url-safety.d.ts +1 -1
  35. package/dist/url-safety.d.ts.map +1 -1
  36. package/dist/url-safety.js +1 -1
  37. package/dist/url-safety.js.map +1 -1
  38. package/package.json +3 -3
  39. package/src/dom-props.ts +189 -49
  40. package/src/element.ts +45 -1
  41. package/src/event-listeners.ts +4 -5
  42. package/src/fiber-child.ts +67 -0
  43. package/src/fiber-commit.ts +92 -0
  44. package/src/hooks.ts +88 -8
  45. package/src/host-reconciler.ts +2 -3
  46. package/src/jsx-runtime.ts +2 -18
  47. package/src/reconciler.ts +2 -3
  48. package/src/server-render.ts +43 -4
  49. package/src/url-safety.ts +1 -0
package/dist/hooks.js CHANGED
@@ -85,6 +85,7 @@ function flushActWork() {
85
85
  export function createRootRuntime(rerender, options = {}) {
86
86
  return {
87
87
  instances: new Map(),
88
+ instanceKeysByPrefix: new Map(),
88
89
  activeInstanceKeys: undefined,
89
90
  activeProfilerPaths: undefined,
90
91
  mountedProfilerPaths: new Set(),
@@ -256,20 +257,25 @@ export function renderWithRootRuntime(runtime, path, render, owner) {
256
257
  hooks: [],
257
258
  hookIndex: 0,
258
259
  dirty: false,
259
- devToolsHooks: [],
260
- devToolsHookTypes: [],
261
260
  devToolsHookSuppressionDepth: 0,
262
261
  };
263
262
  instance.owner = owner;
264
263
  instance.path = path;
265
264
  runtime.instances.set(path, instance);
265
+ indexInstanceKey(runtime, path);
266
266
  runtime.activeInstanceKeys?.add(path);
267
267
  instance.hookIndex = 0;
268
268
  instance.dirty = false;
269
269
  instance.disposed = false;
270
270
  delete instance.contextDependencies;
271
- instance.devToolsHooks = [];
272
- instance.devToolsHookTypes = [];
271
+ if (hasInstalledDevToolsHook()) {
272
+ instance.devToolsHooks = [];
273
+ instance.devToolsHookTypes = [];
274
+ }
275
+ else {
276
+ delete instance.devToolsHooks;
277
+ delete instance.devToolsHookTypes;
278
+ }
273
279
  instance.devToolsHookSuppressionDepth = 0;
274
280
  hookRenderState.currentRuntime = runtime;
275
281
  hookRenderState.currentInstance = instance;
@@ -300,9 +306,24 @@ export function hasChangedContextDependency(runtime, keys) {
300
306
  export function hasContextDependency(runtime, keys) {
301
307
  return keys.some((key) => runtime.instances.get(key)?.contextDependencies !== undefined);
302
308
  }
309
+ export function collectRuntimeInstanceKeys(runtime, prefix) {
310
+ const keys = runtime.instanceKeysByPrefix.get(prefix);
311
+ if (keys === undefined) {
312
+ return [];
313
+ }
314
+ const activeKeys = [];
315
+ for (const key of keys) {
316
+ if (runtime.instances.has(key)) {
317
+ activeKeys.push(key);
318
+ }
319
+ }
320
+ return activeKeys;
321
+ }
303
322
  export function getDevToolsHookState(runtime, path) {
304
323
  const instance = runtime.instances.get(path);
305
- if (instance === undefined) {
324
+ if (instance === undefined ||
325
+ instance.devToolsHooks === undefined ||
326
+ instance.devToolsHookTypes === undefined) {
306
327
  return undefined;
307
328
  }
308
329
  return {
@@ -616,12 +637,18 @@ function assignRef(ref, value) {
616
637
  }
617
638
  function recordDevToolsHook(type, value) {
618
639
  const instance = hookRenderState.currentInstance;
619
- if (instance === undefined || instance.devToolsHookSuppressionDepth > 0) {
640
+ if (instance === undefined ||
641
+ instance.devToolsHookSuppressionDepth > 0 ||
642
+ instance.devToolsHooks === undefined ||
643
+ instance.devToolsHookTypes === undefined) {
620
644
  return;
621
645
  }
622
646
  instance.devToolsHookTypes.push(type);
623
647
  instance.devToolsHooks.push(value);
624
648
  }
649
+ function hasInstalledDevToolsHook() {
650
+ return typeof globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__?.inject === "function";
651
+ }
625
652
  function runWithoutDevToolsHookTracking(callback) {
626
653
  const instance = requireInstance();
627
654
  instance.devToolsHookSuppressionDepth += 1;
@@ -1337,9 +1364,40 @@ function cleanupInactiveInstances(runtime) {
1337
1364
  if (!activeInstanceKeys.has(key)) {
1338
1365
  cleanupInstance(instance);
1339
1366
  runtime.instances.delete(key);
1367
+ removeInstanceKeyFromIndex(runtime, key);
1340
1368
  }
1341
1369
  }
1342
1370
  }
1371
+ function indexInstanceKey(runtime, key) {
1372
+ for (const prefix of instanceKeyPrefixes(key)) {
1373
+ let keys = runtime.instanceKeysByPrefix.get(prefix);
1374
+ if (keys === undefined) {
1375
+ keys = new Set();
1376
+ runtime.instanceKeysByPrefix.set(prefix, keys);
1377
+ }
1378
+ keys.add(key);
1379
+ }
1380
+ }
1381
+ function removeInstanceKeyFromIndex(runtime, key) {
1382
+ for (const prefix of instanceKeyPrefixes(key)) {
1383
+ const keys = runtime.instanceKeysByPrefix.get(prefix);
1384
+ if (keys === undefined) {
1385
+ continue;
1386
+ }
1387
+ keys.delete(key);
1388
+ if (keys.size === 0) {
1389
+ runtime.instanceKeysByPrefix.delete(prefix);
1390
+ }
1391
+ }
1392
+ }
1393
+ function instanceKeyPrefixes(key) {
1394
+ const parts = key.split(".");
1395
+ const prefixes = [];
1396
+ for (let index = 1; index <= parts.length; index += 1) {
1397
+ prefixes.push(parts.slice(0, index).join("."));
1398
+ }
1399
+ return prefixes;
1400
+ }
1343
1401
  function cleanupInstance(instance) {
1344
1402
  instance.disposed = true;
1345
1403
  for (const slot of instance.hooks) {