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.
package/dist/runtime.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import {
2
2
  SUSPENSE_SCRIPT_ATTR,
3
+ SUSPENSE_RESOLVED_COMMENT,
4
+ SUSPENSE_RESOLVED_SEED_ATTR,
5
+ SUSPENSE_RESOLVED_NATIVE_ATTR,
3
6
  HYDRATE_STATIC_ID_COUNT_PREFIX,
4
7
  HYDRATE_STATIC_END,
5
8
  HYDRATE_ID_ATTR,
@@ -1253,6 +1256,8 @@ function journalRootRange(parent, before, after) {
1253
1256
  for (let node = before === null ? parent.firstChild : before.nextSibling; node !== null && node !== after; node = node.nextSibling)
1254
1257
  nodes.push(node);
1255
1258
  journalUndo(() => {
1259
+ if (before !== null && before.parentNode !== parent || after !== null && after.parentNode !== parent)
1260
+ return;
1256
1261
  let node = before !== null && before.parentNode === parent ? before.nextSibling : parent.firstChild;
1257
1262
  const anchor = after !== null && after.parentNode === parent ? after : null;
1258
1263
  const retained = new Set(nodes);
@@ -1631,23 +1636,45 @@ function journalForSlot(state) {
1631
1636
  TRANSITION_JOURNAL_BAGS.delete(state);
1632
1637
  });
1633
1638
  }
1639
+ function journalForOwnedListClear(state) {
1640
+ const seen = TRANSITION_JOURNAL_BAGS;
1641
+ const oldItems = state.items;
1642
+ seen.set(state, TRANSITION_JOURNAL.length);
1643
+ const snapshot = {
1644
+ head: state.head,
1645
+ tail: state.tail,
1646
+ size: state.size,
1647
+ empty: state.emptyBlock,
1648
+ entries: oldItems
1649
+ };
1650
+ journalUndo(() => {
1651
+ restoreForSlot(state, snapshot, null);
1652
+ seen.delete(state);
1653
+ });
1654
+ state.items = /* @__PURE__ */ new Map();
1655
+ }
1634
1656
  function restoreForSlot(state, snapshot, chain) {
1635
- const kept = /* @__PURE__ */ new Set();
1636
- for (let i = 0; i < chain.length; i++) kept.add(chain[i][0]);
1657
+ const preservedMap = chain === null ? snapshot.entries : null;
1658
+ const kept = chain === null ? null : /* @__PURE__ */ new Set();
1659
+ if (chain !== null) for (let i = 0; i < chain.length; i++) kept.add(chain[i][0]);
1637
1660
  for (let b = state.head; b !== null; b = b.nextSibling) {
1638
- if (!kept.has(b)) unmountBlock(b, false);
1661
+ if (preservedMap !== null || !kept.has(b)) unmountBlock(b, false);
1639
1662
  }
1640
1663
  if (state.end.parentNode === null) return;
1641
1664
  state.head = snapshot.head;
1642
1665
  state.tail = snapshot.tail;
1643
1666
  state.size = snapshot.size;
1644
- state.items.clear();
1645
- for (let i = 0; i < snapshot.entries.length; i++) {
1646
- state.items.set(snapshot.entries[i][0], snapshot.entries[i][1]);
1647
- }
1648
- for (let i = 0; i < chain.length; i++) {
1649
- chain[i][0].nextSibling = chain[i][1];
1650
- chain[i][0].prevSibling = chain[i][2];
1667
+ if (preservedMap !== null) state.items = preservedMap;
1668
+ else {
1669
+ const originalChain = chain;
1670
+ state.items.clear();
1671
+ for (let i = 0; i < snapshot.entries.length; i++) {
1672
+ state.items.set(snapshot.entries[i][0], snapshot.entries[i][1]);
1673
+ }
1674
+ for (let i = 0; i < originalChain.length; i++) {
1675
+ originalChain[i][0].nextSibling = originalChain[i][1];
1676
+ originalChain[i][0].prevSibling = originalChain[i][2];
1677
+ }
1651
1678
  }
1652
1679
  const nodes = [];
1653
1680
  for (let b = state.head; b !== null; b = b.nextSibling) {
@@ -2108,6 +2135,12 @@ function reapplyFragmentBindings() {
2108
2135
  }
2109
2136
  let IS_OCTANE_ACT_ENVIRONMENT = false;
2110
2137
  let actScopeDepth = 0;
2138
+ let actCallbackDepth = 0;
2139
+ let asyncActCallbackDepth = 0;
2140
+ let actErrors = null;
2141
+ function isInActScope() {
2142
+ return actCallbackDepth !== 0 || asyncActCallbackDepth !== 0;
2143
+ }
2111
2144
  function setIsOctaneActEnvironment(value) {
2112
2145
  IS_OCTANE_ACT_ENVIRONMENT = value;
2113
2146
  }
@@ -2434,8 +2467,13 @@ function flush() {
2434
2467
  __devtoolsNotifyFlush();
2435
2468
  return;
2436
2469
  }
2437
- if (VIEW_TRANSITION_DRIVER?.routeFlush() === true) return;
2438
- flushWork();
2470
+ try {
2471
+ if (VIEW_TRANSITION_DRIVER?.routeFlush() === true) return;
2472
+ flushWork();
2473
+ } catch (error) {
2474
+ if (actScopeDepth === 0) throw error;
2475
+ (actErrors ??= []).push(error);
2476
+ }
2439
2477
  }
2440
2478
  function activeElementForDocument(doc) {
2441
2479
  try {
@@ -2722,6 +2760,17 @@ function captureFocusedMovement(parent, snapshots) {
2722
2760
  }
2723
2761
  (renderingFocusMoves ??= []).push({ snapshot, ancestors });
2724
2762
  }
2763
+ function drainLayoutUpdates(pendingError) {
2764
+ for (let guard = 0; (QUEUE.length > 0 || ROOT_RENDER_TRANSACTIONS.length > 0) && guard < LAYOUT_CASCADE_LIMIT; guard++) {
2765
+ drainPassivesBeforeRender();
2766
+ const focused = QUEUE.length === 0 ? null : captureQueuedFocusSelection();
2767
+ const error = drainQueueWithFocus(focused);
2768
+ if (focused !== null) restoreQueuedFocusSelection(focused);
2769
+ if (error !== null && pendingError === null) pendingError = error;
2770
+ commitEffects();
2771
+ }
2772
+ return pendingError;
2773
+ }
2725
2774
  function flushWork() {
2726
2775
  inFlush = true;
2727
2776
  const clearRetainedTransitionUpdates = FLUSHED_TRANSITION_UPDATES.length > 0;
@@ -2730,9 +2779,11 @@ function flushWork() {
2730
2779
  try {
2731
2780
  if (QUEUE.length > 0) drainPassivesBeforeRender();
2732
2781
  const focused = QUEUE.length === 0 ? null : captureQueuedFocusSelection();
2733
- const pendingError = drainQueueWithFocus(focused);
2782
+ let pendingError = drainQueueWithFocus(focused);
2734
2783
  if (focused !== null) restoreQueuedFocusSelection(focused);
2735
2784
  commitEffects();
2785
+ if (QUEUE.length > 0 || ROOT_RENDER_TRANSACTIONS.length > 0)
2786
+ pendingError = drainLayoutUpdates(pendingError);
2736
2787
  if (pendingError !== null) throw pendingError.err;
2737
2788
  } finally {
2738
2789
  inFlush = false;
@@ -2957,24 +3008,7 @@ function flushSync(fn) {
2957
3008
  if (focused !== null) restoreQueuedFocusSelection(focused);
2958
3009
  commitEffects();
2959
3010
  if (QUEUE.length > 0 || ROOT_RENDER_TRANSACTIONS.length > 0) {
2960
- const seen = new Set(QUEUE);
2961
- let defer = false;
2962
- for (let guard = 0; (QUEUE.length > 0 || ROOT_RENDER_TRANSACTIONS.length > 0) && !defer && guard < LAYOUT_CASCADE_LIMIT; guard++) {
2963
- drainPassivesBeforeRender();
2964
- const focused2 = QUEUE.length === 0 ? null : captureQueuedFocusSelection();
2965
- const err = drainQueueWithFocus(focused2);
2966
- if (focused2 !== null) restoreQueuedFocusSelection(focused2);
2967
- if (err !== null && pendingError === null) pendingError = err;
2968
- commitEffects();
2969
- for (let i = 0; i < QUEUE.length; i++) {
2970
- const b = QUEUE[i];
2971
- if (seen.has(b)) {
2972
- defer = true;
2973
- break;
2974
- }
2975
- seen.add(b);
2976
- }
2977
- }
3011
+ pendingError = drainLayoutUpdates(pendingError);
2978
3012
  }
2979
3013
  } finally {
2980
3014
  inFlush = false;
@@ -3114,6 +3148,35 @@ function drainRefAttaches() {
3114
3148
  }
3115
3149
  }
3116
3150
  }
3151
+ let refStateUpdates = null;
3152
+ let collectingRefStateUpdates = false;
3153
+ function drainCommitRefs() {
3154
+ const previousUpdates = refStateUpdates;
3155
+ const previousCollecting = collectingRefStateUpdates;
3156
+ refStateUpdates = null;
3157
+ collectingRefStateUpdates = true;
3158
+ try {
3159
+ drainRefDetaches();
3160
+ drainRefAttaches();
3161
+ } finally {
3162
+ const updates = refStateUpdates;
3163
+ refStateUpdates = previousUpdates;
3164
+ collectingRefStateUpdates = previousCollecting;
3165
+ if (updates !== null) {
3166
+ REF_CALLBACK_DEPTH++;
3167
+ try {
3168
+ for (const [state, update] of updates) {
3169
+ if (update.block.disposed || Object.is(state.value, update.previous)) continue;
3170
+ if (typeof __OCTANE_PROFILE_ENABLED__ !== "undefined" && __OCTANE_PROFILE_ENABLED__)
3171
+ __profileSchedule(update.block, "state", update.profileSlot);
3172
+ scheduleRender(update.block);
3173
+ }
3174
+ } finally {
3175
+ REF_CALLBACK_DEPTH--;
3176
+ }
3177
+ }
3178
+ }
3179
+ }
3117
3180
  function blockSubtreeDisposed(block) {
3118
3181
  let b = block;
3119
3182
  while (b !== null) {
@@ -3160,8 +3223,7 @@ function commitEffects() {
3160
3223
  const caughtReports = drainEffectEventCommitActions();
3161
3224
  drainControlledSyncs();
3162
3225
  const mutationBatch = drainMutationEffects();
3163
- drainRefDetaches();
3164
- drainRefAttaches();
3226
+ drainCommitRefs();
3165
3227
  reapplyFragmentBindings();
3166
3228
  if (mutationBatch !== null) runLayoutEffects(mutationBatch);
3167
3229
  if (caughtReports !== null) publishInlineCaughtErrorReports(caughtReports);
@@ -3208,35 +3270,77 @@ function drainEffectEventUpdates() {
3208
3270
  entry.cell.impl = entry.nextImpl;
3209
3271
  }
3210
3272
  }
3273
+ function throwPendingActErrors() {
3274
+ const errors = actErrors;
3275
+ actErrors = null;
3276
+ if (errors !== null)
3277
+ throw errors.length === 1 ? errors[0] : new AggregateError(errors, formatClientError(64));
3278
+ }
3279
+ function mergePendingActErrors(error) {
3280
+ const errors = actErrors;
3281
+ actErrors = null;
3282
+ return errors === null ? error : new AggregateError([...errors, error], formatClientError(64));
3283
+ }
3284
+ function actCheckpoint() {
3285
+ return new Promise((resolve) => {
3286
+ const channel = new MessageChannel();
3287
+ channel.port1.onmessage = () => {
3288
+ channel.port1.close();
3289
+ channel.port2.close();
3290
+ resolve();
3291
+ };
3292
+ channel.port2.postMessage(null);
3293
+ });
3294
+ }
3211
3295
  function act(fn) {
3296
+ const nested = isInActScope();
3212
3297
  actScopeDepth++;
3298
+ actCallbackDepth++;
3213
3299
  let result;
3214
3300
  try {
3215
3301
  result = fn();
3216
3302
  } catch (err) {
3217
3303
  actScopeDepth--;
3218
- return Promise.reject(err);
3304
+ return Promise.reject(mergePendingActErrors(err));
3305
+ } finally {
3306
+ actCallbackDepth--;
3219
3307
  }
3220
3308
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
3309
+ asyncActCallbackDepth++;
3221
3310
  return (async () => {
3222
3311
  try {
3223
- const value = await result;
3312
+ let value;
3313
+ try {
3314
+ value = await result;
3315
+ } finally {
3316
+ asyncActCallbackDepth--;
3317
+ }
3318
+ if (nested) return value;
3224
3319
  for (let i = 0; i < ACT_DRAIN_LIMIT; i++) {
3225
- for (let j = 0; j < 5; j++) await Promise.resolve();
3320
+ await actCheckpoint();
3321
+ throwPendingActErrors();
3322
+ const hadWork = hasPendingWork();
3226
3323
  drainPassiveEffects();
3227
- if (!hasPendingWork()) return value;
3324
+ if (!hadWork && !hasPendingWork()) return value;
3228
3325
  }
3229
3326
  throw new Error(formatClientError(14, ACT_DRAIN_LIMIT));
3327
+ } catch (error) {
3328
+ throw mergePendingActErrors(error);
3230
3329
  } finally {
3231
3330
  actScopeDepth--;
3232
3331
  }
3233
3332
  })();
3234
3333
  }
3334
+ if (nested) {
3335
+ actScopeDepth--;
3336
+ return Promise.resolve(result);
3337
+ }
3235
3338
  try {
3236
3339
  for (let i = 0; i < ACT_DRAIN_LIMIT; i++) {
3237
3340
  if (VIEW_TRANSITION_DRIVER?.wouldWrap() === true) flush();
3238
3341
  else flushSync(() => {
3239
3342
  });
3343
+ throwPendingActErrors();
3240
3344
  drainPassiveEffects();
3241
3345
  if (!hasPendingWork()) break;
3242
3346
  if (i === ACT_DRAIN_LIMIT - 1) {
@@ -3245,16 +3349,20 @@ function act(fn) {
3245
3349
  }
3246
3350
  } catch (err) {
3247
3351
  actScopeDepth--;
3248
- return Promise.reject(err);
3352
+ return Promise.reject(mergePendingActErrors(err));
3249
3353
  }
3250
3354
  return (async () => {
3251
3355
  try {
3252
3356
  for (let i = 0; i < ACT_DRAIN_LIMIT; i++) {
3253
- for (let j = 0; j < 5; j++) await Promise.resolve();
3357
+ await actCheckpoint();
3358
+ throwPendingActErrors();
3359
+ const hadWork = hasPendingWork();
3254
3360
  drainPassiveEffects();
3255
- if (!hasPendingWork()) return result;
3361
+ if (!hadWork && !hasPendingWork()) return result;
3256
3362
  }
3257
3363
  throw new Error(formatClientError(14, ACT_DRAIN_LIMIT));
3364
+ } catch (error) {
3365
+ throw mergePendingActErrors(error);
3258
3366
  } finally {
3259
3367
  actScopeDepth--;
3260
3368
  }
@@ -3709,19 +3817,51 @@ function createBlock(kind, parentBlock, parentNode, startMarker, endMarker, body
3709
3817
  }
3710
3818
  return block;
3711
3819
  }
3820
+ let renderPhaseOwner = null;
3821
+ let renderPhaseUpdates = null;
3822
+ function captureRenderPhaseUpdate(cell, key) {
3823
+ const updates = renderPhaseUpdates ??= /* @__PURE__ */ new Map();
3824
+ if (!updates.has(cell)) updates.set(cell, { value: cell.value, queue: cell[key]?.slice(), key });
3825
+ }
3712
3826
  function renderBlock(block) {
3713
3827
  const hydration = activeHydration();
3714
3828
  if (hydration !== null && !hydration.owns(block)) {
3715
3829
  hydration.suspend(() => renderBlock(block));
3716
3830
  return;
3717
3831
  }
3718
- let retries = 0;
3719
- while (renderBlockInner(block)) {
3720
- if (block.nestedUpdateError) {
3721
- block.nestedUpdateError = false;
3722
- throw maximumUpdateDepthError();
3832
+ const previousOwner = renderPhaseOwner;
3833
+ let previousUpdates = renderPhaseUpdates;
3834
+ renderPhaseOwner = block;
3835
+ renderPhaseUpdates = null;
3836
+ try {
3837
+ let retries = 0;
3838
+ while (renderBlockInner(block)) {
3839
+ if (block.nestedUpdateError) {
3840
+ block.nestedUpdateError = false;
3841
+ throw maximumUpdateDepthError();
3842
+ }
3843
+ if (++retries > RENDER_PHASE_UPDATE_LIMIT) throw new Error(formatClientError(9));
3844
+ }
3845
+ const updates = renderPhaseUpdates;
3846
+ if (updates !== null && previousOwner !== null && blockIsAncestorOf(previousOwner, block)) {
3847
+ previousUpdates ??= /* @__PURE__ */ new Map();
3848
+ for (const [cell, snapshot] of updates) {
3849
+ if (!previousUpdates.has(cell)) previousUpdates.set(cell, snapshot);
3850
+ }
3851
+ }
3852
+ } catch (error) {
3853
+ const updates = renderPhaseUpdates;
3854
+ if (updates !== null) {
3855
+ for (const [cell, snapshot] of updates) {
3856
+ cell.value = snapshot.value;
3857
+ cell[snapshot.key] = snapshot.queue;
3858
+ }
3859
+ if (!block.crossRenderUpdate) block.pending = false;
3723
3860
  }
3724
- if (++retries > RENDER_PHASE_UPDATE_LIMIT) throw new Error(formatClientError(9));
3861
+ throw error;
3862
+ } finally {
3863
+ renderPhaseOwner = previousOwner;
3864
+ renderPhaseUpdates = previousUpdates;
3725
3865
  }
3726
3866
  }
3727
3867
  function enqueueEffectEventUpdate(entry) {
@@ -4401,6 +4541,9 @@ function manualHook(fn, name) {
4401
4541
  Object.defineProperty(provider, "length", { value: fn.length, configurable: true });
4402
4542
  return provider;
4403
4543
  }
4544
+ function callWithReceiver(fn, receiver, ...args) {
4545
+ return NATIVE_REFLECT_APPLY(fn, receiver, args);
4546
+ }
4404
4547
  function withSlot(sym, fn, ...args) {
4405
4548
  const driver = MANUAL_HOOK_DRIVER;
4406
4549
  const pending = driver?.pending;
@@ -4466,6 +4609,7 @@ function useState(initial, slot) {
4466
4609
  if (s.pendingActionBatch !== void 0 && transitionActionBatchForUpdate() === null)
4467
4610
  recordUrgentActionUpdate(s, next);
4468
4611
  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) {
4612
+ if (CURRENT_BLOCK === block) captureRenderPhaseUpdate(s, "updates");
4469
4613
  (s.updates ??= []).push(next);
4470
4614
  scheduleRender(block);
4471
4615
  return;
@@ -4477,6 +4621,7 @@ function useState(initial, slot) {
4477
4621
  computed = typeof next === "function" ? next(previous) : next;
4478
4622
  } catch {
4479
4623
  if (transitionActionBatchForUpdate() === null) {
4624
+ if (CURRENT_BLOCK === block) captureRenderPhaseUpdate(s, "updates");
4480
4625
  (s.updates ??= []).push(next);
4481
4626
  scheduleRender(block);
4482
4627
  return;
@@ -4503,6 +4648,19 @@ function useState(initial, slot) {
4503
4648
  }
4504
4649
  return;
4505
4650
  }
4651
+ if (collectingRefStateUpdates && REF_CALLBACK_DEPTH > 0 && !forceRender) {
4652
+ const updates = refStateUpdates ??= /* @__PURE__ */ new Map();
4653
+ const state = s;
4654
+ if (!updates.has(state)) {
4655
+ const update2 = { block, previous: s.value };
4656
+ if (typeof __OCTANE_PROFILE_ENABLED__ !== "undefined" && __OCTANE_PROFILE_ENABLED__)
4657
+ update2.profileSlot = slot;
4658
+ updates.set(state, update2);
4659
+ }
4660
+ s.value = computed;
4661
+ return;
4662
+ }
4663
+ if (CURRENT_BLOCK === block) captureRenderPhaseUpdate(s, "updates");
4506
4664
  s.value = computed;
4507
4665
  if (!block.disposed && typeof __OCTANE_PROFILE_ENABLED__ !== "undefined" && __OCTANE_PROFILE_ENABLED__)
4508
4666
  __profileSchedule(block, "state", slot);
@@ -4835,6 +4993,7 @@ function useReducer(reducer, initialArg, initOrSlot, slot) {
4835
4993
  dispatch: (action) => {
4836
4994
  if (block.disposed) return;
4837
4995
  if (CURRENT_BLOCK === block || transitionActionBatchForUpdate() === null) {
4996
+ if (CURRENT_BLOCK === block) captureRenderPhaseUpdate(s, "renderPhaseActions");
4838
4997
  if (s.pendingActionBatch !== void 0 && transitionActionBatchForUpdate() === null)
4839
4998
  recordUrgentActionUpdate(s, (value) => s.reducer(value, action));
4840
4999
  const actions = s.renderPhaseActions ??= [];
@@ -7810,6 +7969,7 @@ class HydrationCapability {
7810
7969
  this.rootBlock = rootBlock;
7811
7970
  this.node = node;
7812
7971
  this.seeds = seeds;
7972
+ initialSuspenseHydrationRenderer = renderInitialSuspenseHydration;
7813
7973
  }
7814
7974
  rootBlock;
7815
7975
  node;
@@ -10819,6 +10979,10 @@ function buildDelegatedPath(event, listener, path = event.composedPath()) {
10819
10979
  }
10820
10980
  }
10821
10981
  function fireEventSlot(slot, event) {
10982
+ const previousScope = CURRENT_SCOPE;
10983
+ const previousBlock = CURRENT_BLOCK;
10984
+ CURRENT_SCOPE = null;
10985
+ CURRENT_BLOCK = null;
10822
10986
  try {
10823
10987
  if (typeof slot === "function") {
10824
10988
  slot(event);
@@ -10849,6 +11013,9 @@ function fireEventSlot(slot, event) {
10849
11013
  invokeInvalidEventListener(`${event.type} event`, slot, event);
10850
11014
  } catch (err) {
10851
11015
  reportListenerError(err);
11016
+ } finally {
11017
+ CURRENT_SCOPE = previousScope;
11018
+ CURRENT_BLOCK = previousBlock;
10852
11019
  }
10853
11020
  }
10854
11021
  function invokeInvalidEventListener(label, listener, event) {
@@ -10877,7 +11044,7 @@ function reportListenerError(err) {
10877
11044
  }
10878
11045
  function maybeFlushDiscrete(type) {
10879
11046
  if (_dispatchDepth === 0 && DISCRETE_EVENTS.has(type) && pendingRestores.length > 0) {
10880
- if (hasPendingWork()) {
11047
+ if (!inFlush && hasPendingWork()) {
10881
11048
  if (VIEW_TRANSITION_DRIVER?.queueAllTransition() === true) flush();
10882
11049
  else flushSync(noop);
10883
11050
  }
@@ -15884,6 +16051,7 @@ function releaseHiddenText(text, restore = true) {
15884
16051
  }
15885
16052
  }
15886
16053
  function teardownTrySlot(state, detachDom) {
16054
+ initialSuspenseHydrations?.delete(state);
15887
16055
  cancelSuspenseRetry(state);
15888
16056
  HIDDEN_REVEAL_ACTIONS?.delete(state);
15889
16057
  if (state.block !== null) unmountBlock(state.block, detachDom);
@@ -16355,6 +16523,15 @@ function tryBlock(parentScope, slotKey, domParent, tryBody, catchBody, pendingBo
16355
16523
  state.env = env;
16356
16524
  }
16357
16525
  const s = state;
16526
+ let initial = initialSuspenseHydrations?.get(s);
16527
+ if (initial === void 0 && hydration !== null && s.branch === -1 && !s.propagateSuspense) {
16528
+ initial = takeInitialSuspenseHydration(s, hydration) ?? void 0;
16529
+ if (initial !== void 0) (initialSuspenseHydrations ??= /* @__PURE__ */ new WeakMap()).set(s, initial);
16530
+ }
16531
+ if (initial !== void 0) {
16532
+ initialSuspenseHydrationRenderer(s, initial);
16533
+ return s.reset;
16534
+ }
16358
16535
  if (s.passthrough) {
16359
16536
  renderPassthroughTry(s);
16360
16537
  return s.reset;
@@ -16472,6 +16649,184 @@ function mountHiddenTryBody(state) {
16472
16649
  hideTryBlock(state);
16473
16650
  return block;
16474
16651
  }
16652
+ let initialSuspenseHydrations = null;
16653
+ let initialStreamedPayloads = null;
16654
+ let initialSuspenseHydrationRenderer = null;
16655
+ function takeInitialSuspenseHydration(state, hydration) {
16656
+ const marker = state.start.nextSibling;
16657
+ if (marker?.nodeType !== 8) return null;
16658
+ const text = marker.data;
16659
+ if (text.startsWith(STREAM_SEED_COMMENT)) {
16660
+ const boundaryId = text.slice(STREAM_SEED_COMMENT.length);
16661
+ const start = marker.nextSibling;
16662
+ if (!hydration.isOpen(start)) return null;
16663
+ const end2 = hydration.close(start);
16664
+ const stash = typeof window !== "undefined" ? window.$OCTS : void 0;
16665
+ const owner = marker;
16666
+ let payload = initialStreamedPayloads?.get(owner);
16667
+ if (payload === void 0) {
16668
+ payload = {
16669
+ seedRaw: typeof stash?.[boundaryId] === "string" ? stash[boundaryId] : null,
16670
+ nativeRaw: typeof stash?.[boundaryId + "$signals"] === "string" ? stash[boundaryId + "$signals"] : null
16671
+ };
16672
+ (initialStreamedPayloads ??= /* @__PURE__ */ new WeakMap()).set(owner, payload);
16673
+ if (stash !== void 0) {
16674
+ delete stash[boundaryId];
16675
+ delete stash[boundaryId + "$signals"];
16676
+ }
16677
+ }
16678
+ state.idState = {
16679
+ prefix: state.parentBlock.idState.prefix + "b" + boundaryId + "-",
16680
+ next: 0,
16681
+ renderOwner: state.parentBlock.idState.renderOwner
16682
+ };
16683
+ return {
16684
+ metadata: [marker],
16685
+ start,
16686
+ end: end2,
16687
+ idStart: 0,
16688
+ ...payload,
16689
+ consume: () => {
16690
+ initialStreamedPayloads?.delete(owner);
16691
+ }
16692
+ };
16693
+ }
16694
+ if (!text.startsWith(SUSPENSE_RESOLVED_COMMENT)) return null;
16695
+ const rawCount = text.slice(SUSPENSE_RESOLVED_COMMENT.length);
16696
+ if (!/^(?:0|[1-9]\d*)$/.test(rawCount)) return null;
16697
+ const count = Number(rawCount);
16698
+ if (!Number.isSafeInteger(count)) return null;
16699
+ let cursor = marker.nextSibling;
16700
+ let seedRaw = null;
16701
+ let nativeRaw = null;
16702
+ const sidecars = [];
16703
+ for (const attr of [SUSPENSE_RESOLVED_SEED_ATTR, SUSPENSE_RESOLVED_NATIVE_ATTR]) {
16704
+ if (cursor?.nodeType !== 1) continue;
16705
+ const script = cursor;
16706
+ if (script.localName !== "script" || script.getAttribute("type") !== "application/json" || !script.hasAttribute(attr))
16707
+ continue;
16708
+ if (attr === SUSPENSE_RESOLVED_SEED_ATTR) seedRaw = script.textContent;
16709
+ else nativeRaw = script.textContent;
16710
+ sidecars.push(script);
16711
+ cursor = script.nextSibling;
16712
+ }
16713
+ if (!hydration.isOpen(cursor)) return null;
16714
+ const end = hydration.close(cursor);
16715
+ const rootIds = state.idState;
16716
+ const idStart = rootIds.next;
16717
+ reserveHydrationIds(rootIds, count);
16718
+ state.idState = {
16719
+ prefix: rootIds.prefix,
16720
+ next: idStart,
16721
+ limit: idStart + count,
16722
+ overflow: rootIds,
16723
+ renderOwner: rootIds.renderOwner
16724
+ };
16725
+ return {
16726
+ metadata: [marker, ...sidecars],
16727
+ start: cursor,
16728
+ end,
16729
+ idStart,
16730
+ seedRaw,
16731
+ nativeRaw
16732
+ };
16733
+ }
16734
+ function finishInitialSuspenseHydration(initial, hydration) {
16735
+ for (const node of initial.metadata) node.remove();
16736
+ initial.consume?.();
16737
+ if (hydration.hasAdjacentRangePair) hydration.coalesce();
16738
+ }
16739
+ function renderInitialSuspenseHydration(state, initial) {
16740
+ state.pendingThenable = null;
16741
+ state.idState.next = initial.idStart;
16742
+ const block = createTryBody(state, initial.start, initial.end);
16743
+ state.block = block;
16744
+ setTryBranch(state, 1);
16745
+ const hydration = new HydrationCapability(block, initial.start.nextSibling, null);
16746
+ if (initial.seedRaw !== null) hydration.seeds = hydration.parseSeeds(initial.seedRaw);
16747
+ hydration.claimRootRemainder(initial.end);
16748
+ hydration.protectRootAnchor(initial.end);
16749
+ const previousHydration = currentHydration;
16750
+ const previousCapture = WIP_CAPTURE;
16751
+ const capture = createOffscreenCapture();
16752
+ currentHydration = hydration;
16753
+ WIP_CAPTURE = capture;
16754
+ const previousNative = setNativeAdoptionResolver(null);
16755
+ let suspended = null;
16756
+ let failed = false;
16757
+ let failure;
16758
+ try {
16759
+ if (initial.nativeRaw !== null) {
16760
+ hydration.nativeAdoption = ownNativeAdoption(
16761
+ block,
16762
+ parseNativeSignalManifest(initial.nativeRaw)
16763
+ );
16764
+ setNativeAdoptionResolver(hydration.nativeAdoption.resolve);
16765
+ }
16766
+ renderBlock(block);
16767
+ drainHydrationRenderPhaseUpdates(block);
16768
+ hydration.flushClassWrites();
16769
+ hydration.flushTextWarnings();
16770
+ state.hasResolved = true;
16771
+ } catch (error) {
16772
+ failed = true;
16773
+ failure = error;
16774
+ if (isSuspenseException(error)) suspended = error.thenable;
16775
+ const refs = [];
16776
+ collectVisibleSubtreeRefs(block, refs);
16777
+ withRefDetachSuppression(refs, () => unmountBlock(block, false));
16778
+ state.block = null;
16779
+ state.tryBlock = null;
16780
+ discardOffscreenCapture(capture);
16781
+ } finally {
16782
+ setNativeAdoptionResolver(previousNative);
16783
+ WIP_CAPTURE = previousCapture;
16784
+ currentHydration = previousHydration;
16785
+ if (previousHydration !== null) previousHydration.node = state.end;
16786
+ }
16787
+ if (!failed) {
16788
+ initialSuspenseHydrations?.delete(state);
16789
+ (capture.renderCleanups ??= []).push((discarded) => {
16790
+ if (discarded) return;
16791
+ finishInitialSuspenseHydration(initial, hydration);
16792
+ });
16793
+ spliceOffscreenCapture(capture);
16794
+ return;
16795
+ }
16796
+ if (suspended !== null) {
16797
+ state.pendingThenable = suspended;
16798
+ const resume = () => {
16799
+ if (state.parentBlock.disposed || state.pendingThenable !== suspended || initialSuspenseHydrations?.get(state) !== initial)
16800
+ return;
16801
+ scheduleRender(state.parentBlock);
16802
+ };
16803
+ suspended.then(resume, resume);
16804
+ return;
16805
+ }
16806
+ initialSuspenseHydrations?.delete(state);
16807
+ if (failure instanceof NativeAdoptionMiss || isHostContextRequest(failure)) throw failure;
16808
+ const adoptServerCatch = hydration.isRejection(failure);
16809
+ if (!adoptServerCatch) removeRange(initial.start.nextSibling, initial.end);
16810
+ const outerHydration = currentHydration;
16811
+ if (adoptServerCatch) currentHydration = hydration;
16812
+ try {
16813
+ switchToCatch(
16814
+ state,
16815
+ failure,
16816
+ true,
16817
+ adoptServerCatch ? initial.start : void 0,
16818
+ adoptServerCatch ? initial.end : void 0
16819
+ );
16820
+ if (WIP_CAPTURE === null) finishInitialSuspenseHydration(initial, hydration);
16821
+ else
16822
+ (WIP_CAPTURE.renderCleanups ??= []).push((discarded) => {
16823
+ if (!discarded) finishInitialSuspenseHydration(initial, hydration);
16824
+ });
16825
+ } finally {
16826
+ currentHydration = outerHydration;
16827
+ if (outerHydration !== null) outerHydration.node = state.end;
16828
+ }
16829
+ }
16475
16830
  function mountTry(state) {
16476
16831
  cancelSuspenseRetry(state);
16477
16832
  HIDDEN_REVEAL_ACTIONS?.delete(state);
@@ -17999,6 +18354,9 @@ function switchToCatchInner(state, err, reportInline, adoptedStart, adoptedEnd)
17999
18354
  );
18000
18355
  b.idState = state.idState;
18001
18356
  state.block = b;
18357
+ if (adopting && hydration !== null && hydration.rootBlock.disposed && hydration.rootBlock.startMarker === bStart && hydration.rootBlock.endMarker === bEnd) {
18358
+ hydration.rootBlock = b;
18359
+ }
18002
18360
  try {
18003
18361
  if (!adopting && hydration !== null) hydration.suspend(() => renderBlock(b));
18004
18362
  else renderBlock(b);
@@ -19069,8 +19427,9 @@ function switchBlock(parentScope, slotKey, domParent, discriminant, cases, defau
19069
19427
  }
19070
19428
  renderBranchSlot(parentScope, slotKey, state, domParent, nextIdx, body, "switch", env);
19071
19429
  }
19072
- function forBlock(parentScope, slotKey, domParent, items, getKey, itemBody, flags, deps, emptyBody, anchor, ownEnd) {
19430
+ function forBlock(parentScope, slotKey, domParent, inputItems, getKey, itemBody, flags, deps, emptyBody, anchor, ownEnd) {
19073
19431
  if (CURRENT_BLOCK?.pending && !CURRENT_BLOCK.crossRenderUpdate) return;
19432
+ const items = Array.isArray(inputItems) ? inputItems : Array.from(inputItems);
19074
19433
  const parentBlock = parentScope.block;
19075
19434
  const hydration = activeHydration();
19076
19435
  let state = parentScope.slots[slotKey];
@@ -19645,8 +20004,11 @@ function reconcileKeyed(parentBlock, state, items, getKey, itemBody, pure, singl
19645
20004
  }
19646
20005
  if (process.env.NODE_ENV !== "production") getKey = checkedListKey(getKey);
19647
20006
  if (newLen === 0) {
19648
- if (journalShape) journalForSlot(state);
19649
- batchClearItems(state, oldItems);
20007
+ const ownedRootClear = journalShape && canDeferRootOwnedListClear(state);
20008
+ if (ownedRootClear && (TRANSITION_JOURNAL_BAGS.get(state) ?? -1) < TRANSITION_JOURNAL_CHECKPOINT)
20009
+ journalForOwnedListClear(state);
20010
+ else if (journalShape) journalForSlot(state);
20011
+ batchClearItems(state, ownedRootClear ? state.items : oldItems, ownedRootClear);
19650
20012
  state.head = null;
19651
20013
  state.tail = null;
19652
20014
  state.size = 0;
@@ -19975,8 +20337,76 @@ function reconcileKeyed(parentBlock, state, items, getKey, itemBody, pure, singl
19975
20337
  }
19976
20338
  }
19977
20339
  const RANGE_CLEAR_MIN_ITEMS = 512;
19978
- function batchClearItems(state, oldItems) {
20340
+ function canDeferRootOwnedListClear(state) {
20341
+ const transaction = ROOT_RENDER_TRANSACTION;
20342
+ const parent = state.start.parentNode;
20343
+ 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)
20344
+ return false;
20345
+ const oldHead = state.head;
20346
+ for (let block = oldHead; block !== null; block = block.nextSibling) {
20347
+ 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)
20348
+ return false;
20349
+ }
20350
+ return true;
20351
+ }
20352
+ function deferRootOwnedListClear(state, certified = false) {
20353
+ if (!certified && !canDeferRootOwnedListClear(state)) return false;
20354
+ const transaction = ROOT_RENDER_TRANSACTION;
20355
+ const parent = state.start.parentNode;
20356
+ const oldHead = state.head;
20357
+ const retired = transaction.retired ??= /* @__PURE__ */ new Set();
20358
+ const newlyRetired = [];
20359
+ for (let block = oldHead; block !== null; block = block.nextSibling) {
20360
+ if (!retired.has(block)) {
20361
+ retired.add(block);
20362
+ newlyRetired.push(block);
20363
+ }
20364
+ if (block.pending) {
20365
+ journalRootProperty(block, "pending");
20366
+ block.pending = false;
20367
+ }
20368
+ }
20369
+ let cancelled = false;
20370
+ journalUndo(() => {
20371
+ cancelled = true;
20372
+ for (let i = 0; i < newlyRetired.length; i++) retired.delete(newlyRetired[i]);
20373
+ });
20374
+ const start = state.start;
20375
+ const end = state.end;
20376
+ (transaction.commit ??= []).push(() => {
20377
+ if (cancelled) return;
20378
+ let wholeParent = state.size === 0 && start.parentNode === parent && end.parentNode === parent && start.previousSibling === null && end.nextSibling === null;
20379
+ if (wholeParent) {
20380
+ let node = start.nextSibling;
20381
+ for (let block = oldHead; block !== null; block = block.nextSibling) {
20382
+ if (node !== block.startMarker) {
20383
+ wholeParent = false;
20384
+ break;
20385
+ }
20386
+ node = node.nextSibling;
20387
+ }
20388
+ if (node !== end) wholeParent = false;
20389
+ }
20390
+ for (let block = oldHead; block !== null; block = block.nextSibling) block.disposed = true;
20391
+ if (wholeParent) {
20392
+ parent.textContent = "";
20393
+ parent.appendChild(start);
20394
+ parent.appendChild(end);
20395
+ } else {
20396
+ for (let block = oldHead; block !== null; block = block.nextSibling) {
20397
+ const node = block.startMarker;
20398
+ if (node.parentNode !== null) node.parentNode.removeChild(node);
20399
+ }
20400
+ }
20401
+ });
20402
+ return true;
20403
+ }
20404
+ function batchClearItems(state, oldItems, ownedRootClear = false) {
19979
20405
  if (forSlotParkable(state)) {
20406
+ if (deferRootOwnedListClear(state, ownedRootClear)) {
20407
+ oldItems.clear();
20408
+ return;
20409
+ }
19980
20410
  let next;
19981
20411
  for (let b = state.head; b !== null; b = next) {
19982
20412
  next = b.nextSibling;
@@ -21678,6 +22108,7 @@ export {
21678
22108
  beginNativeReadScope,
21679
22109
  beginNativeReadWitness,
21680
22110
  bindRendererRegionOwner,
22111
+ callWithReceiver,
21681
22112
  child,
21682
22113
  childSlot,
21683
22114
  childTextHole,
@@ -21747,6 +22178,7 @@ export {
21747
22178
  injectStyle,
21748
22179
  invokeManualHook,
21749
22180
  isChildrenBlock,
22181
+ isInActScope,
21750
22182
  isValidElement,
21751
22183
  keyedForBlock,
21752
22184
  lazy,