octane 0.2.4 → 0.2.6

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.
@@ -61,6 +61,7 @@ __export(runtime_exports, {
61
61
  beginNativeReadScope: () => beginNativeReadScope,
62
62
  beginNativeReadWitness: () => beginNativeReadWitness,
63
63
  bindRendererRegionOwner: () => bindRendererRegionOwner,
64
+ callWithReceiver: () => callWithReceiver,
64
65
  child: () => child,
65
66
  childSlot: () => childSlot,
66
67
  childTextHole: () => childTextHole,
@@ -130,6 +131,7 @@ __export(runtime_exports, {
130
131
  injectStyle: () => injectStyle,
131
132
  invokeManualHook: () => invokeManualHook,
132
133
  isChildrenBlock: () => isChildrenBlock,
134
+ isInActScope: () => isInActScope,
133
135
  isValidElement: () => isValidElement,
134
136
  keyedForBlock: () => keyedForBlock,
135
137
  lazy: () => lazy,
@@ -1423,6 +1425,8 @@ function journalRootRange(parent, before, after) {
1423
1425
  for (let node = before === null ? parent.firstChild : before.nextSibling; node !== null && node !== after; node = node.nextSibling)
1424
1426
  nodes.push(node);
1425
1427
  journalUndo(() => {
1428
+ if (before !== null && before.parentNode !== parent || after !== null && after.parentNode !== parent)
1429
+ return;
1426
1430
  let node = before !== null && before.parentNode === parent ? before.nextSibling : parent.firstChild;
1427
1431
  const anchor = after !== null && after.parentNode === parent ? after : null;
1428
1432
  const retained = new Set(nodes);
@@ -1801,23 +1805,45 @@ function journalForSlot(state) {
1801
1805
  TRANSITION_JOURNAL_BAGS.delete(state);
1802
1806
  });
1803
1807
  }
1808
+ function journalForOwnedListClear(state) {
1809
+ const seen = TRANSITION_JOURNAL_BAGS;
1810
+ const oldItems = state.items;
1811
+ seen.set(state, TRANSITION_JOURNAL.length);
1812
+ const snapshot = {
1813
+ head: state.head,
1814
+ tail: state.tail,
1815
+ size: state.size,
1816
+ empty: state.emptyBlock,
1817
+ entries: oldItems
1818
+ };
1819
+ journalUndo(() => {
1820
+ restoreForSlot(state, snapshot, null);
1821
+ seen.delete(state);
1822
+ });
1823
+ state.items = /* @__PURE__ */ new Map();
1824
+ }
1804
1825
  function restoreForSlot(state, snapshot, chain) {
1805
- const kept = /* @__PURE__ */ new Set();
1806
- for (let i = 0; i < chain.length; i++) kept.add(chain[i][0]);
1826
+ const preservedMap = chain === null ? snapshot.entries : null;
1827
+ const kept = chain === null ? null : /* @__PURE__ */ new Set();
1828
+ if (chain !== null) for (let i = 0; i < chain.length; i++) kept.add(chain[i][0]);
1807
1829
  for (let b = state.head; b !== null; b = b.nextSibling) {
1808
- if (!kept.has(b)) unmountBlock(b, false);
1830
+ if (preservedMap !== null || !kept.has(b)) unmountBlock(b, false);
1809
1831
  }
1810
1832
  if (state.end.parentNode === null) return;
1811
1833
  state.head = snapshot.head;
1812
1834
  state.tail = snapshot.tail;
1813
1835
  state.size = snapshot.size;
1814
- state.items.clear();
1815
- for (let i = 0; i < snapshot.entries.length; i++) {
1816
- state.items.set(snapshot.entries[i][0], snapshot.entries[i][1]);
1817
- }
1818
- for (let i = 0; i < chain.length; i++) {
1819
- chain[i][0].nextSibling = chain[i][1];
1820
- chain[i][0].prevSibling = chain[i][2];
1836
+ if (preservedMap !== null) state.items = preservedMap;
1837
+ else {
1838
+ const originalChain = chain;
1839
+ state.items.clear();
1840
+ for (let i = 0; i < snapshot.entries.length; i++) {
1841
+ state.items.set(snapshot.entries[i][0], snapshot.entries[i][1]);
1842
+ }
1843
+ for (let i = 0; i < originalChain.length; i++) {
1844
+ originalChain[i][0].nextSibling = originalChain[i][1];
1845
+ originalChain[i][0].prevSibling = originalChain[i][2];
1846
+ }
1821
1847
  }
1822
1848
  const nodes = [];
1823
1849
  for (let b = state.head; b !== null; b = b.nextSibling) {
@@ -2278,6 +2304,12 @@ function reapplyFragmentBindings() {
2278
2304
  }
2279
2305
  let IS_OCTANE_ACT_ENVIRONMENT = false;
2280
2306
  let actScopeDepth = 0;
2307
+ let actCallbackDepth = 0;
2308
+ let asyncActCallbackDepth = 0;
2309
+ let actErrors = null;
2310
+ function isInActScope() {
2311
+ return actCallbackDepth !== 0 || asyncActCallbackDepth !== 0;
2312
+ }
2281
2313
  function setIsOctaneActEnvironment(value) {
2282
2314
  IS_OCTANE_ACT_ENVIRONMENT = value;
2283
2315
  }
@@ -2604,8 +2636,13 @@ function flush() {
2604
2636
  (0, import_devtools_hook.__devtoolsNotifyFlush)();
2605
2637
  return;
2606
2638
  }
2607
- if (VIEW_TRANSITION_DRIVER?.routeFlush() === true) return;
2608
- flushWork();
2639
+ try {
2640
+ if (VIEW_TRANSITION_DRIVER?.routeFlush() === true) return;
2641
+ flushWork();
2642
+ } catch (error) {
2643
+ if (actScopeDepth === 0) throw error;
2644
+ (actErrors ??= []).push(error);
2645
+ }
2609
2646
  }
2610
2647
  function activeElementForDocument(doc) {
2611
2648
  try {
@@ -2892,6 +2929,17 @@ function captureFocusedMovement(parent, snapshots) {
2892
2929
  }
2893
2930
  (renderingFocusMoves ??= []).push({ snapshot, ancestors });
2894
2931
  }
2932
+ function drainLayoutUpdates(pendingError) {
2933
+ for (let guard = 0; (QUEUE.length > 0 || ROOT_RENDER_TRANSACTIONS.length > 0) && guard < LAYOUT_CASCADE_LIMIT; guard++) {
2934
+ drainPassivesBeforeRender();
2935
+ const focused = QUEUE.length === 0 ? null : captureQueuedFocusSelection();
2936
+ const error = drainQueueWithFocus(focused);
2937
+ if (focused !== null) restoreQueuedFocusSelection(focused);
2938
+ if (error !== null && pendingError === null) pendingError = error;
2939
+ commitEffects();
2940
+ }
2941
+ return pendingError;
2942
+ }
2895
2943
  function flushWork() {
2896
2944
  inFlush = true;
2897
2945
  const clearRetainedTransitionUpdates = FLUSHED_TRANSITION_UPDATES.length > 0;
@@ -2900,9 +2948,11 @@ function flushWork() {
2900
2948
  try {
2901
2949
  if (QUEUE.length > 0) drainPassivesBeforeRender();
2902
2950
  const focused = QUEUE.length === 0 ? null : captureQueuedFocusSelection();
2903
- const pendingError = drainQueueWithFocus(focused);
2951
+ let pendingError = drainQueueWithFocus(focused);
2904
2952
  if (focused !== null) restoreQueuedFocusSelection(focused);
2905
2953
  commitEffects();
2954
+ if (QUEUE.length > 0 || ROOT_RENDER_TRANSACTIONS.length > 0)
2955
+ pendingError = drainLayoutUpdates(pendingError);
2906
2956
  if (pendingError !== null) throw pendingError.err;
2907
2957
  } finally {
2908
2958
  inFlush = false;
@@ -3127,24 +3177,7 @@ function flushSync(fn) {
3127
3177
  if (focused !== null) restoreQueuedFocusSelection(focused);
3128
3178
  commitEffects();
3129
3179
  if (QUEUE.length > 0 || ROOT_RENDER_TRANSACTIONS.length > 0) {
3130
- const seen = new Set(QUEUE);
3131
- let defer = false;
3132
- for (let guard = 0; (QUEUE.length > 0 || ROOT_RENDER_TRANSACTIONS.length > 0) && !defer && guard < LAYOUT_CASCADE_LIMIT; guard++) {
3133
- drainPassivesBeforeRender();
3134
- const focused2 = QUEUE.length === 0 ? null : captureQueuedFocusSelection();
3135
- const err = drainQueueWithFocus(focused2);
3136
- if (focused2 !== null) restoreQueuedFocusSelection(focused2);
3137
- if (err !== null && pendingError === null) pendingError = err;
3138
- commitEffects();
3139
- for (let i = 0; i < QUEUE.length; i++) {
3140
- const b = QUEUE[i];
3141
- if (seen.has(b)) {
3142
- defer = true;
3143
- break;
3144
- }
3145
- seen.add(b);
3146
- }
3147
- }
3180
+ pendingError = drainLayoutUpdates(pendingError);
3148
3181
  }
3149
3182
  } finally {
3150
3183
  inFlush = false;
@@ -3284,6 +3317,35 @@ function drainRefAttaches() {
3284
3317
  }
3285
3318
  }
3286
3319
  }
3320
+ let refStateUpdates = null;
3321
+ let collectingRefStateUpdates = false;
3322
+ function drainCommitRefs() {
3323
+ const previousUpdates = refStateUpdates;
3324
+ const previousCollecting = collectingRefStateUpdates;
3325
+ refStateUpdates = null;
3326
+ collectingRefStateUpdates = true;
3327
+ try {
3328
+ drainRefDetaches();
3329
+ drainRefAttaches();
3330
+ } finally {
3331
+ const updates = refStateUpdates;
3332
+ refStateUpdates = previousUpdates;
3333
+ collectingRefStateUpdates = previousCollecting;
3334
+ if (updates !== null) {
3335
+ REF_CALLBACK_DEPTH++;
3336
+ try {
3337
+ for (const [state, update] of updates) {
3338
+ if (update.block.disposed || Object.is(state.value, update.previous)) continue;
3339
+ if (typeof __OCTANE_PROFILE_ENABLED__ !== "undefined" && __OCTANE_PROFILE_ENABLED__)
3340
+ (0, import_profiling.__profileSchedule)(update.block, "state", update.profileSlot);
3341
+ scheduleRender(update.block);
3342
+ }
3343
+ } finally {
3344
+ REF_CALLBACK_DEPTH--;
3345
+ }
3346
+ }
3347
+ }
3348
+ }
3287
3349
  function blockSubtreeDisposed(block) {
3288
3350
  let b = block;
3289
3351
  while (b !== null) {
@@ -3330,8 +3392,7 @@ function commitEffects() {
3330
3392
  const caughtReports = drainEffectEventCommitActions();
3331
3393
  drainControlledSyncs();
3332
3394
  const mutationBatch = drainMutationEffects();
3333
- drainRefDetaches();
3334
- drainRefAttaches();
3395
+ drainCommitRefs();
3335
3396
  reapplyFragmentBindings();
3336
3397
  if (mutationBatch !== null) runLayoutEffects(mutationBatch);
3337
3398
  if (caughtReports !== null) publishInlineCaughtErrorReports(caughtReports);
@@ -3378,35 +3439,77 @@ function drainEffectEventUpdates() {
3378
3439
  entry.cell.impl = entry.nextImpl;
3379
3440
  }
3380
3441
  }
3442
+ function throwPendingActErrors() {
3443
+ const errors = actErrors;
3444
+ actErrors = null;
3445
+ if (errors !== null)
3446
+ throw errors.length === 1 ? errors[0] : new AggregateError(errors, (0, import_error_codes_client_generated.formatClientError)(64));
3447
+ }
3448
+ function mergePendingActErrors(error) {
3449
+ const errors = actErrors;
3450
+ actErrors = null;
3451
+ return errors === null ? error : new AggregateError([...errors, error], (0, import_error_codes_client_generated.formatClientError)(64));
3452
+ }
3453
+ function actCheckpoint() {
3454
+ return new Promise((resolve) => {
3455
+ const channel = new MessageChannel();
3456
+ channel.port1.onmessage = () => {
3457
+ channel.port1.close();
3458
+ channel.port2.close();
3459
+ resolve();
3460
+ };
3461
+ channel.port2.postMessage(null);
3462
+ });
3463
+ }
3381
3464
  function act(fn) {
3465
+ const nested = isInActScope();
3382
3466
  actScopeDepth++;
3467
+ actCallbackDepth++;
3383
3468
  let result;
3384
3469
  try {
3385
3470
  result = fn();
3386
3471
  } catch (err) {
3387
3472
  actScopeDepth--;
3388
- return Promise.reject(err);
3473
+ return Promise.reject(mergePendingActErrors(err));
3474
+ } finally {
3475
+ actCallbackDepth--;
3389
3476
  }
3390
3477
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
3478
+ asyncActCallbackDepth++;
3391
3479
  return (async () => {
3392
3480
  try {
3393
- const value = await result;
3481
+ let value;
3482
+ try {
3483
+ value = await result;
3484
+ } finally {
3485
+ asyncActCallbackDepth--;
3486
+ }
3487
+ if (nested) return value;
3394
3488
  for (let i = 0; i < ACT_DRAIN_LIMIT; i++) {
3395
- for (let j = 0; j < 5; j++) await Promise.resolve();
3489
+ await actCheckpoint();
3490
+ throwPendingActErrors();
3491
+ const hadWork = hasPendingWork();
3396
3492
  drainPassiveEffects();
3397
- if (!hasPendingWork()) return value;
3493
+ if (!hadWork && !hasPendingWork()) return value;
3398
3494
  }
3399
3495
  throw new Error((0, import_error_codes_client_generated.formatClientError)(14, ACT_DRAIN_LIMIT));
3496
+ } catch (error) {
3497
+ throw mergePendingActErrors(error);
3400
3498
  } finally {
3401
3499
  actScopeDepth--;
3402
3500
  }
3403
3501
  })();
3404
3502
  }
3503
+ if (nested) {
3504
+ actScopeDepth--;
3505
+ return Promise.resolve(result);
3506
+ }
3405
3507
  try {
3406
3508
  for (let i = 0; i < ACT_DRAIN_LIMIT; i++) {
3407
3509
  if (VIEW_TRANSITION_DRIVER?.wouldWrap() === true) flush();
3408
3510
  else flushSync(() => {
3409
3511
  });
3512
+ throwPendingActErrors();
3410
3513
  drainPassiveEffects();
3411
3514
  if (!hasPendingWork()) break;
3412
3515
  if (i === ACT_DRAIN_LIMIT - 1) {
@@ -3415,16 +3518,20 @@ function act(fn) {
3415
3518
  }
3416
3519
  } catch (err) {
3417
3520
  actScopeDepth--;
3418
- return Promise.reject(err);
3521
+ return Promise.reject(mergePendingActErrors(err));
3419
3522
  }
3420
3523
  return (async () => {
3421
3524
  try {
3422
3525
  for (let i = 0; i < ACT_DRAIN_LIMIT; i++) {
3423
- for (let j = 0; j < 5; j++) await Promise.resolve();
3526
+ await actCheckpoint();
3527
+ throwPendingActErrors();
3528
+ const hadWork = hasPendingWork();
3424
3529
  drainPassiveEffects();
3425
- if (!hasPendingWork()) return result;
3530
+ if (!hadWork && !hasPendingWork()) return result;
3426
3531
  }
3427
3532
  throw new Error((0, import_error_codes_client_generated.formatClientError)(14, ACT_DRAIN_LIMIT));
3533
+ } catch (error) {
3534
+ throw mergePendingActErrors(error);
3428
3535
  } finally {
3429
3536
  actScopeDepth--;
3430
3537
  }
@@ -3879,19 +3986,51 @@ function createBlock(kind, parentBlock, parentNode, startMarker, endMarker, body
3879
3986
  }
3880
3987
  return block;
3881
3988
  }
3989
+ let renderPhaseOwner = null;
3990
+ let renderPhaseUpdates = null;
3991
+ function captureRenderPhaseUpdate(cell, key) {
3992
+ const updates = renderPhaseUpdates ??= /* @__PURE__ */ new Map();
3993
+ if (!updates.has(cell)) updates.set(cell, { value: cell.value, queue: cell[key]?.slice(), key });
3994
+ }
3882
3995
  function renderBlock(block) {
3883
3996
  const hydration = activeHydration();
3884
3997
  if (hydration !== null && !hydration.owns(block)) {
3885
3998
  hydration.suspend(() => renderBlock(block));
3886
3999
  return;
3887
4000
  }
3888
- let retries = 0;
3889
- while (renderBlockInner(block)) {
3890
- if (block.nestedUpdateError) {
3891
- block.nestedUpdateError = false;
3892
- throw maximumUpdateDepthError();
4001
+ const previousOwner = renderPhaseOwner;
4002
+ let previousUpdates = renderPhaseUpdates;
4003
+ renderPhaseOwner = block;
4004
+ renderPhaseUpdates = null;
4005
+ try {
4006
+ let retries = 0;
4007
+ while (renderBlockInner(block)) {
4008
+ if (block.nestedUpdateError) {
4009
+ block.nestedUpdateError = false;
4010
+ throw maximumUpdateDepthError();
4011
+ }
4012
+ if (++retries > RENDER_PHASE_UPDATE_LIMIT) throw new Error((0, import_error_codes_client_generated.formatClientError)(9));
4013
+ }
4014
+ const updates = renderPhaseUpdates;
4015
+ if (updates !== null && previousOwner !== null && blockIsAncestorOf(previousOwner, block)) {
4016
+ previousUpdates ??= /* @__PURE__ */ new Map();
4017
+ for (const [cell, snapshot] of updates) {
4018
+ if (!previousUpdates.has(cell)) previousUpdates.set(cell, snapshot);
4019
+ }
4020
+ }
4021
+ } catch (error) {
4022
+ const updates = renderPhaseUpdates;
4023
+ if (updates !== null) {
4024
+ for (const [cell, snapshot] of updates) {
4025
+ cell.value = snapshot.value;
4026
+ cell[snapshot.key] = snapshot.queue;
4027
+ }
4028
+ if (!block.crossRenderUpdate) block.pending = false;
3893
4029
  }
3894
- if (++retries > RENDER_PHASE_UPDATE_LIMIT) throw new Error((0, import_error_codes_client_generated.formatClientError)(9));
4030
+ throw error;
4031
+ } finally {
4032
+ renderPhaseOwner = previousOwner;
4033
+ renderPhaseUpdates = previousUpdates;
3895
4034
  }
3896
4035
  }
3897
4036
  function enqueueEffectEventUpdate(entry) {
@@ -4571,6 +4710,9 @@ function manualHook(fn, name) {
4571
4710
  Object.defineProperty(provider, "length", { value: fn.length, configurable: true });
4572
4711
  return provider;
4573
4712
  }
4713
+ function callWithReceiver(fn, receiver, ...args) {
4714
+ return NATIVE_REFLECT_APPLY(fn, receiver, args);
4715
+ }
4574
4716
  function withSlot(sym, fn, ...args) {
4575
4717
  const driver = MANUAL_HOOK_DRIVER;
4576
4718
  const pending = driver?.pending;
@@ -4636,6 +4778,7 @@ function useState(initial, slot) {
4636
4778
  if (s.pendingActionBatch !== void 0 && transitionActionBatchForUpdate() === null)
4637
4779
  recordUrgentActionUpdate(s, next);
4638
4780
  if ((s.updates !== void 0 || s.renderTransition !== void 0 || typeof next === "function" && TRANSITION_PENDING_COUNT > 0 && TRANSITION_SWAP_DRIVER?.hasHeld(s, block) || block.pending && typeof next === "function") && transitionActionBatchForUpdate() === null) {
4781
+ if (CURRENT_BLOCK === block) captureRenderPhaseUpdate(s, "updates");
4639
4782
  (s.updates ??= []).push(next);
4640
4783
  scheduleRender(block);
4641
4784
  return;
@@ -4647,6 +4790,7 @@ function useState(initial, slot) {
4647
4790
  computed = typeof next === "function" ? next(previous) : next;
4648
4791
  } catch {
4649
4792
  if (transitionActionBatchForUpdate() === null) {
4793
+ if (CURRENT_BLOCK === block) captureRenderPhaseUpdate(s, "updates");
4650
4794
  (s.updates ??= []).push(next);
4651
4795
  scheduleRender(block);
4652
4796
  return;
@@ -4673,6 +4817,19 @@ function useState(initial, slot) {
4673
4817
  }
4674
4818
  return;
4675
4819
  }
4820
+ if (collectingRefStateUpdates && REF_CALLBACK_DEPTH > 0 && !forceRender) {
4821
+ const updates = refStateUpdates ??= /* @__PURE__ */ new Map();
4822
+ const state = s;
4823
+ if (!updates.has(state)) {
4824
+ const update2 = { block, previous: s.value };
4825
+ if (typeof __OCTANE_PROFILE_ENABLED__ !== "undefined" && __OCTANE_PROFILE_ENABLED__)
4826
+ update2.profileSlot = slot;
4827
+ updates.set(state, update2);
4828
+ }
4829
+ s.value = computed;
4830
+ return;
4831
+ }
4832
+ if (CURRENT_BLOCK === block) captureRenderPhaseUpdate(s, "updates");
4676
4833
  s.value = computed;
4677
4834
  if (!block.disposed && typeof __OCTANE_PROFILE_ENABLED__ !== "undefined" && __OCTANE_PROFILE_ENABLED__)
4678
4835
  (0, import_profiling.__profileSchedule)(block, "state", slot);
@@ -5005,6 +5162,7 @@ function useReducer(reducer, initialArg, initOrSlot, slot) {
5005
5162
  dispatch: (action) => {
5006
5163
  if (block.disposed) return;
5007
5164
  if (CURRENT_BLOCK === block || transitionActionBatchForUpdate() === null) {
5165
+ if (CURRENT_BLOCK === block) captureRenderPhaseUpdate(s, "renderPhaseActions");
5008
5166
  if (s.pendingActionBatch !== void 0 && transitionActionBatchForUpdate() === null)
5009
5167
  recordUrgentActionUpdate(s, (value) => s.reducer(value, action));
5010
5168
  const actions = s.renderPhaseActions ??= [];
@@ -7980,6 +8138,7 @@ class HydrationCapability {
7980
8138
  this.rootBlock = rootBlock;
7981
8139
  this.node = node;
7982
8140
  this.seeds = seeds;
8141
+ initialSuspenseHydrationRenderer = renderInitialSuspenseHydration;
7983
8142
  }
7984
8143
  rootBlock;
7985
8144
  node;
@@ -10982,6 +11141,10 @@ function buildDelegatedPath(event, listener, path = event.composedPath()) {
10982
11141
  }
10983
11142
  }
10984
11143
  function fireEventSlot(slot, event) {
11144
+ const previousScope = CURRENT_SCOPE;
11145
+ const previousBlock = CURRENT_BLOCK;
11146
+ CURRENT_SCOPE = null;
11147
+ CURRENT_BLOCK = null;
10985
11148
  try {
10986
11149
  if (typeof slot === "function") {
10987
11150
  slot(event);
@@ -11012,6 +11175,9 @@ function fireEventSlot(slot, event) {
11012
11175
  invokeInvalidEventListener(`${event.type} event`, slot, event);
11013
11176
  } catch (err) {
11014
11177
  reportListenerError(err);
11178
+ } finally {
11179
+ CURRENT_SCOPE = previousScope;
11180
+ CURRENT_BLOCK = previousBlock;
11015
11181
  }
11016
11182
  }
11017
11183
  function invokeInvalidEventListener(label, listener, event) {
@@ -11040,7 +11206,7 @@ function reportListenerError(err) {
11040
11206
  }
11041
11207
  function maybeFlushDiscrete(type) {
11042
11208
  if (_dispatchDepth === 0 && DISCRETE_EVENTS.has(type) && pendingRestores.length > 0) {
11043
- if (hasPendingWork()) {
11209
+ if (!inFlush && hasPendingWork()) {
11044
11210
  if (VIEW_TRANSITION_DRIVER?.queueAllTransition() === true) flush();
11045
11211
  else flushSync(noop);
11046
11212
  }
@@ -16047,6 +16213,7 @@ function releaseHiddenText(text, restore = true) {
16047
16213
  }
16048
16214
  }
16049
16215
  function teardownTrySlot(state, detachDom) {
16216
+ initialSuspenseHydrations?.delete(state);
16050
16217
  cancelSuspenseRetry(state);
16051
16218
  HIDDEN_REVEAL_ACTIONS?.delete(state);
16052
16219
  if (state.block !== null) unmountBlock(state.block, detachDom);
@@ -16518,6 +16685,15 @@ function tryBlock(parentScope, slotKey, domParent, tryBody, catchBody, pendingBo
16518
16685
  state.env = env;
16519
16686
  }
16520
16687
  const s = state;
16688
+ let initial = initialSuspenseHydrations?.get(s);
16689
+ if (initial === void 0 && hydration !== null && s.branch === -1 && !s.propagateSuspense) {
16690
+ initial = takeInitialSuspenseHydration(s, hydration) ?? void 0;
16691
+ if (initial !== void 0) (initialSuspenseHydrations ??= /* @__PURE__ */ new WeakMap()).set(s, initial);
16692
+ }
16693
+ if (initial !== void 0) {
16694
+ initialSuspenseHydrationRenderer(s, initial);
16695
+ return s.reset;
16696
+ }
16521
16697
  if (s.passthrough) {
16522
16698
  renderPassthroughTry(s);
16523
16699
  return s.reset;
@@ -16635,6 +16811,184 @@ function mountHiddenTryBody(state) {
16635
16811
  hideTryBlock(state);
16636
16812
  return block;
16637
16813
  }
16814
+ let initialSuspenseHydrations = null;
16815
+ let initialStreamedPayloads = null;
16816
+ let initialSuspenseHydrationRenderer = null;
16817
+ function takeInitialSuspenseHydration(state, hydration) {
16818
+ const marker = state.start.nextSibling;
16819
+ if (marker?.nodeType !== 8) return null;
16820
+ const text = marker.data;
16821
+ if (text.startsWith(import_constants.STREAM_SEED_COMMENT)) {
16822
+ const boundaryId = text.slice(import_constants.STREAM_SEED_COMMENT.length);
16823
+ const start = marker.nextSibling;
16824
+ if (!hydration.isOpen(start)) return null;
16825
+ const end2 = hydration.close(start);
16826
+ const stash = typeof window !== "undefined" ? window.$OCTS : void 0;
16827
+ const owner = marker;
16828
+ let payload = initialStreamedPayloads?.get(owner);
16829
+ if (payload === void 0) {
16830
+ payload = {
16831
+ seedRaw: typeof stash?.[boundaryId] === "string" ? stash[boundaryId] : null,
16832
+ nativeRaw: typeof stash?.[boundaryId + "$signals"] === "string" ? stash[boundaryId + "$signals"] : null
16833
+ };
16834
+ (initialStreamedPayloads ??= /* @__PURE__ */ new WeakMap()).set(owner, payload);
16835
+ if (stash !== void 0) {
16836
+ delete stash[boundaryId];
16837
+ delete stash[boundaryId + "$signals"];
16838
+ }
16839
+ }
16840
+ state.idState = {
16841
+ prefix: state.parentBlock.idState.prefix + "b" + boundaryId + "-",
16842
+ next: 0,
16843
+ renderOwner: state.parentBlock.idState.renderOwner
16844
+ };
16845
+ return {
16846
+ metadata: [marker],
16847
+ start,
16848
+ end: end2,
16849
+ idStart: 0,
16850
+ ...payload,
16851
+ consume: () => {
16852
+ initialStreamedPayloads?.delete(owner);
16853
+ }
16854
+ };
16855
+ }
16856
+ if (!text.startsWith(import_constants.SUSPENSE_RESOLVED_COMMENT)) return null;
16857
+ const rawCount = text.slice(import_constants.SUSPENSE_RESOLVED_COMMENT.length);
16858
+ if (!/^(?:0|[1-9]\d*)$/.test(rawCount)) return null;
16859
+ const count = Number(rawCount);
16860
+ if (!Number.isSafeInteger(count)) return null;
16861
+ let cursor = marker.nextSibling;
16862
+ let seedRaw = null;
16863
+ let nativeRaw = null;
16864
+ const sidecars = [];
16865
+ for (const attr of [import_constants.SUSPENSE_RESOLVED_SEED_ATTR, import_constants.SUSPENSE_RESOLVED_NATIVE_ATTR]) {
16866
+ if (cursor?.nodeType !== 1) continue;
16867
+ const script = cursor;
16868
+ if (script.localName !== "script" || script.getAttribute("type") !== "application/json" || !script.hasAttribute(attr))
16869
+ continue;
16870
+ if (attr === import_constants.SUSPENSE_RESOLVED_SEED_ATTR) seedRaw = script.textContent;
16871
+ else nativeRaw = script.textContent;
16872
+ sidecars.push(script);
16873
+ cursor = script.nextSibling;
16874
+ }
16875
+ if (!hydration.isOpen(cursor)) return null;
16876
+ const end = hydration.close(cursor);
16877
+ const rootIds = state.idState;
16878
+ const idStart = rootIds.next;
16879
+ reserveHydrationIds(rootIds, count);
16880
+ state.idState = {
16881
+ prefix: rootIds.prefix,
16882
+ next: idStart,
16883
+ limit: idStart + count,
16884
+ overflow: rootIds,
16885
+ renderOwner: rootIds.renderOwner
16886
+ };
16887
+ return {
16888
+ metadata: [marker, ...sidecars],
16889
+ start: cursor,
16890
+ end,
16891
+ idStart,
16892
+ seedRaw,
16893
+ nativeRaw
16894
+ };
16895
+ }
16896
+ function finishInitialSuspenseHydration(initial, hydration) {
16897
+ for (const node of initial.metadata) node.remove();
16898
+ initial.consume?.();
16899
+ if (hydration.hasAdjacentRangePair) hydration.coalesce();
16900
+ }
16901
+ function renderInitialSuspenseHydration(state, initial) {
16902
+ state.pendingThenable = null;
16903
+ state.idState.next = initial.idStart;
16904
+ const block = createTryBody(state, initial.start, initial.end);
16905
+ state.block = block;
16906
+ setTryBranch(state, 1);
16907
+ const hydration = new HydrationCapability(block, initial.start.nextSibling, null);
16908
+ if (initial.seedRaw !== null) hydration.seeds = hydration.parseSeeds(initial.seedRaw);
16909
+ hydration.claimRootRemainder(initial.end);
16910
+ hydration.protectRootAnchor(initial.end);
16911
+ const previousHydration = currentHydration;
16912
+ const previousCapture = WIP_CAPTURE;
16913
+ const capture = createOffscreenCapture();
16914
+ currentHydration = hydration;
16915
+ WIP_CAPTURE = capture;
16916
+ const previousNative = (0, import_read_protocol.setNativeAdoptionResolver)(null);
16917
+ let suspended = null;
16918
+ let failed = false;
16919
+ let failure;
16920
+ try {
16921
+ if (initial.nativeRaw !== null) {
16922
+ hydration.nativeAdoption = ownNativeAdoption(
16923
+ block,
16924
+ (0, import_native_read_seeds.parseNativeSignalManifest)(initial.nativeRaw)
16925
+ );
16926
+ (0, import_read_protocol.setNativeAdoptionResolver)(hydration.nativeAdoption.resolve);
16927
+ }
16928
+ renderBlock(block);
16929
+ drainHydrationRenderPhaseUpdates(block);
16930
+ hydration.flushClassWrites();
16931
+ hydration.flushTextWarnings();
16932
+ state.hasResolved = true;
16933
+ } catch (error) {
16934
+ failed = true;
16935
+ failure = error;
16936
+ if (isSuspenseException(error)) suspended = error.thenable;
16937
+ const refs = [];
16938
+ collectVisibleSubtreeRefs(block, refs);
16939
+ withRefDetachSuppression(refs, () => unmountBlock(block, false));
16940
+ state.block = null;
16941
+ state.tryBlock = null;
16942
+ discardOffscreenCapture(capture);
16943
+ } finally {
16944
+ (0, import_read_protocol.setNativeAdoptionResolver)(previousNative);
16945
+ WIP_CAPTURE = previousCapture;
16946
+ currentHydration = previousHydration;
16947
+ if (previousHydration !== null) previousHydration.node = state.end;
16948
+ }
16949
+ if (!failed) {
16950
+ initialSuspenseHydrations?.delete(state);
16951
+ (capture.renderCleanups ??= []).push((discarded) => {
16952
+ if (discarded) return;
16953
+ finishInitialSuspenseHydration(initial, hydration);
16954
+ });
16955
+ spliceOffscreenCapture(capture);
16956
+ return;
16957
+ }
16958
+ if (suspended !== null) {
16959
+ state.pendingThenable = suspended;
16960
+ const resume = () => {
16961
+ if (state.parentBlock.disposed || state.pendingThenable !== suspended || initialSuspenseHydrations?.get(state) !== initial)
16962
+ return;
16963
+ scheduleRender(state.parentBlock);
16964
+ };
16965
+ suspended.then(resume, resume);
16966
+ return;
16967
+ }
16968
+ initialSuspenseHydrations?.delete(state);
16969
+ if (failure instanceof import_read_protocol.NativeAdoptionMiss || isHostContextRequest(failure)) throw failure;
16970
+ const adoptServerCatch = hydration.isRejection(failure);
16971
+ if (!adoptServerCatch) removeRange(initial.start.nextSibling, initial.end);
16972
+ const outerHydration = currentHydration;
16973
+ if (adoptServerCatch) currentHydration = hydration;
16974
+ try {
16975
+ switchToCatch(
16976
+ state,
16977
+ failure,
16978
+ true,
16979
+ adoptServerCatch ? initial.start : void 0,
16980
+ adoptServerCatch ? initial.end : void 0
16981
+ );
16982
+ if (WIP_CAPTURE === null) finishInitialSuspenseHydration(initial, hydration);
16983
+ else
16984
+ (WIP_CAPTURE.renderCleanups ??= []).push((discarded) => {
16985
+ if (!discarded) finishInitialSuspenseHydration(initial, hydration);
16986
+ });
16987
+ } finally {
16988
+ currentHydration = outerHydration;
16989
+ if (outerHydration !== null) outerHydration.node = state.end;
16990
+ }
16991
+ }
16638
16992
  function mountTry(state) {
16639
16993
  cancelSuspenseRetry(state);
16640
16994
  HIDDEN_REVEAL_ACTIONS?.delete(state);
@@ -18162,6 +18516,9 @@ function switchToCatchInner(state, err, reportInline, adoptedStart, adoptedEnd)
18162
18516
  );
18163
18517
  b.idState = state.idState;
18164
18518
  state.block = b;
18519
+ if (adopting && hydration !== null && hydration.rootBlock.disposed && hydration.rootBlock.startMarker === bStart && hydration.rootBlock.endMarker === bEnd) {
18520
+ hydration.rootBlock = b;
18521
+ }
18165
18522
  try {
18166
18523
  if (!adopting && hydration !== null) hydration.suspend(() => renderBlock(b));
18167
18524
  else renderBlock(b);
@@ -19232,8 +19589,9 @@ function switchBlock(parentScope, slotKey, domParent, discriminant, cases, defau
19232
19589
  }
19233
19590
  renderBranchSlot(parentScope, slotKey, state, domParent, nextIdx, body, "switch", env);
19234
19591
  }
19235
- function forBlock(parentScope, slotKey, domParent, items, getKey, itemBody, flags, deps, emptyBody, anchor, ownEnd) {
19592
+ function forBlock(parentScope, slotKey, domParent, inputItems, getKey, itemBody, flags, deps, emptyBody, anchor, ownEnd) {
19236
19593
  if (CURRENT_BLOCK?.pending && !CURRENT_BLOCK.crossRenderUpdate) return;
19594
+ const items = Array.isArray(inputItems) ? inputItems : Array.from(inputItems);
19237
19595
  const parentBlock = parentScope.block;
19238
19596
  const hydration = activeHydration();
19239
19597
  let state = parentScope.slots[slotKey];
@@ -19808,8 +20166,11 @@ function reconcileKeyed(parentBlock, state, items, getKey, itemBody, pure, singl
19808
20166
  }
19809
20167
  if (process.env.NODE_ENV !== "production") getKey = checkedListKey(getKey);
19810
20168
  if (newLen === 0) {
19811
- if (journalShape) journalForSlot(state);
19812
- batchClearItems(state, oldItems);
20169
+ const ownedRootClear = journalShape && canDeferRootOwnedListClear(state);
20170
+ if (ownedRootClear && (TRANSITION_JOURNAL_BAGS.get(state) ?? -1) < TRANSITION_JOURNAL_CHECKPOINT)
20171
+ journalForOwnedListClear(state);
20172
+ else if (journalShape) journalForSlot(state);
20173
+ batchClearItems(state, ownedRootClear ? state.items : oldItems, ownedRootClear);
19813
20174
  state.head = null;
19814
20175
  state.tail = null;
19815
20176
  state.size = 0;
@@ -20138,8 +20499,76 @@ function reconcileKeyed(parentBlock, state, items, getKey, itemBody, pure, singl
20138
20499
  }
20139
20500
  }
20140
20501
  const RANGE_CLEAR_MIN_ITEMS = 512;
20141
- function batchClearItems(state, oldItems) {
20502
+ function canDeferRootOwnedListClear(state) {
20503
+ const transaction = ROOT_RENDER_TRANSACTION;
20504
+ const parent = state.start.parentNode;
20505
+ if (transaction === null || transaction.aborted || ROOT_RENDER_ROLLBACK || transaction.hydrating === true || state.adopt !== null || state.size < 16 || parent === null || parent.nodeType !== 1 && parent.nodeType !== 11 || state.end.parentNode !== parent || state.start.previousSibling !== null || state.end.nextSibling !== null)
20506
+ return false;
20507
+ const oldHead = state.head;
20508
+ for (let block = oldHead; block !== null; block = block.nextSibling) {
20509
+ if (!block.mounted || block.idState.renderOwner !== transaction.owner || block.startMarker === null || block.startMarker !== block.endMarker || block.hooks !== null || block.effectSlots !== null || block.cleanups !== null || block.children !== null || block._slots !== null || block.refFields !== null || block.deoptNode !== null || block.vt !== null)
20510
+ return false;
20511
+ }
20512
+ return true;
20513
+ }
20514
+ function deferRootOwnedListClear(state, certified = false) {
20515
+ if (!certified && !canDeferRootOwnedListClear(state)) return false;
20516
+ const transaction = ROOT_RENDER_TRANSACTION;
20517
+ const parent = state.start.parentNode;
20518
+ const oldHead = state.head;
20519
+ const retired = transaction.retired ??= /* @__PURE__ */ new Set();
20520
+ const newlyRetired = [];
20521
+ for (let block = oldHead; block !== null; block = block.nextSibling) {
20522
+ if (!retired.has(block)) {
20523
+ retired.add(block);
20524
+ newlyRetired.push(block);
20525
+ }
20526
+ if (block.pending) {
20527
+ journalRootProperty(block, "pending");
20528
+ block.pending = false;
20529
+ }
20530
+ }
20531
+ let cancelled = false;
20532
+ journalUndo(() => {
20533
+ cancelled = true;
20534
+ for (let i = 0; i < newlyRetired.length; i++) retired.delete(newlyRetired[i]);
20535
+ });
20536
+ const start = state.start;
20537
+ const end = state.end;
20538
+ (transaction.commit ??= []).push(() => {
20539
+ if (cancelled) return;
20540
+ let wholeParent = state.size === 0 && start.parentNode === parent && end.parentNode === parent && start.previousSibling === null && end.nextSibling === null;
20541
+ if (wholeParent) {
20542
+ let node = start.nextSibling;
20543
+ for (let block = oldHead; block !== null; block = block.nextSibling) {
20544
+ if (node !== block.startMarker) {
20545
+ wholeParent = false;
20546
+ break;
20547
+ }
20548
+ node = node.nextSibling;
20549
+ }
20550
+ if (node !== end) wholeParent = false;
20551
+ }
20552
+ for (let block = oldHead; block !== null; block = block.nextSibling) block.disposed = true;
20553
+ if (wholeParent) {
20554
+ parent.textContent = "";
20555
+ parent.appendChild(start);
20556
+ parent.appendChild(end);
20557
+ } else {
20558
+ for (let block = oldHead; block !== null; block = block.nextSibling) {
20559
+ const node = block.startMarker;
20560
+ if (node.parentNode !== null) node.parentNode.removeChild(node);
20561
+ }
20562
+ }
20563
+ });
20564
+ return true;
20565
+ }
20566
+ function batchClearItems(state, oldItems, ownedRootClear = false) {
20142
20567
  if (forSlotParkable(state)) {
20568
+ if (deferRootOwnedListClear(state, ownedRootClear)) {
20569
+ oldItems.clear();
20570
+ return;
20571
+ }
20143
20572
  let next;
20144
20573
  for (let b = state.head; b !== null; b = next) {
20145
20574
  next = b.nextSibling;
@@ -21842,6 +22271,7 @@ function scriptResource(attrs) {
21842
22271
  beginNativeReadScope,
21843
22272
  beginNativeReadWitness,
21844
22273
  bindRendererRegionOwner,
22274
+ callWithReceiver,
21845
22275
  child,
21846
22276
  childSlot,
21847
22277
  childTextHole,
@@ -21911,6 +22341,7 @@ function scriptResource(attrs) {
21911
22341
  injectStyle,
21912
22342
  invokeManualHook,
21913
22343
  isChildrenBlock,
22344
+ isInActScope,
21914
22345
  isValidElement,
21915
22346
  keyedForBlock,
21916
22347
  lazy,