octane 0.2.12 → 0.2.13

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 (243) hide show
  1. package/README.md +5 -0
  2. package/dist/behavior-root.d.ts +13 -3
  3. package/dist/behavior-root.js +28 -5
  4. package/dist/cjs/behavior-root.cjs +32 -6
  5. package/dist/cjs/class-names.cjs +49 -0
  6. package/dist/cjs/constants.cjs +9 -0
  7. package/dist/cjs/css.cjs +6 -27
  8. package/dist/cjs/data-encoding.cjs +160 -0
  9. package/dist/cjs/dom-binding-handoff.cjs +93 -0
  10. package/dist/cjs/dom-binding-protocol.cjs +115 -0
  11. package/dist/cjs/dom-binding-styles.cjs +292 -0
  12. package/dist/cjs/dom-bindings.cjs +700 -0
  13. package/dist/cjs/dom-focused-move.cjs +66 -0
  14. package/dist/cjs/dom-tables.cjs +4 -94
  15. package/dist/cjs/error-codes.client.generated.cjs +33 -0
  16. package/dist/cjs/error-codes.server.generated.cjs +19 -0
  17. package/dist/cjs/hydration/control-capture.cjs +244 -0
  18. package/dist/cjs/hydration/event-capture.cjs +125 -43
  19. package/dist/cjs/hydration/interaction-config.cjs +50 -2
  20. package/dist/cjs/hydration-markers.cjs +37 -0
  21. package/dist/cjs/independent-hydration-protocol.cjs +106 -0
  22. package/dist/cjs/index.cjs +6 -0
  23. package/dist/cjs/runtime.cjs +2791 -215
  24. package/dist/cjs/runtime.server.cjs +716 -76
  25. package/dist/cjs/server/early-signals.cjs +45 -0
  26. package/dist/cjs/server/index.cjs +44 -0
  27. package/dist/cjs/server/rpc-batch.cjs +149 -0
  28. package/dist/cjs/server/rpc-stream.cjs +146 -0
  29. package/dist/cjs/server/rpc.cjs +34 -15
  30. package/dist/cjs/server/signal-query-observation.cjs +158 -0
  31. package/dist/cjs/server/streamed-region.cjs +52 -0
  32. package/dist/cjs/server/streamed-signals.cjs +512 -0
  33. package/dist/cjs/server-call.cjs +103 -0
  34. package/dist/cjs/server-rpc-batch-client.cjs +141 -0
  35. package/dist/cjs/server-rpc-client.cjs +94 -27
  36. package/dist/cjs/server-rpc-protocol.cjs +141 -0
  37. package/dist/cjs/server-rpc-stream-client.cjs +118 -0
  38. package/dist/cjs/signals/actions.cjs +474 -0
  39. package/dist/cjs/signals/client.cjs +4 -1
  40. package/dist/cjs/signals/computations.cjs +460 -0
  41. package/dist/cjs/signals/control-binding.cjs +368 -0
  42. package/dist/cjs/signals/derived-facade.cjs +50 -0
  43. package/dist/cjs/signals/document-owner.cjs +71 -0
  44. package/dist/cjs/signals/early-values.cjs +155 -0
  45. package/dist/cjs/signals/encoding.cjs +6 -95
  46. package/dist/cjs/signals/engine.cjs +276 -12
  47. package/dist/cjs/signals/errors.cjs +18 -0
  48. package/dist/cjs/signals/facade.cjs +477 -0
  49. package/dist/cjs/signals/graph.cjs +163 -20
  50. package/dist/cjs/signals/handle-protocol.cjs +36 -0
  51. package/dist/cjs/signals/index.cjs +81 -2
  52. package/dist/cjs/signals/native-read-client.cjs +10 -0
  53. package/dist/cjs/signals/owner-context.cjs +112 -0
  54. package/dist/cjs/signals/query-attempt-observer.cjs +68 -0
  55. package/dist/cjs/signals/query-facade.cjs +72 -0
  56. package/dist/cjs/signals/read-protocol.cjs +32 -0
  57. package/dist/cjs/signals/requests.cjs +287 -14
  58. package/dist/cjs/signals/scalar-computations.cjs +76 -0
  59. package/dist/cjs/signals/server.cjs +4 -1
  60. package/dist/cjs/signals/transition-candidate.cjs +567 -0
  61. package/dist/cjs/signals/transition-state.cjs +106 -0
  62. package/dist/cjs/signals/types.cjs +50 -0
  63. package/dist/cjs/stream-protocol.cjs +3 -0
  64. package/dist/cjs/streamed-signals-protocol.cjs +159 -0
  65. package/dist/cjs/style-values.cjs +122 -0
  66. package/dist/cjs/version.cjs +1 -1
  67. package/dist/class-names.d.ts +5 -0
  68. package/dist/class-names.js +25 -0
  69. package/dist/compiler/bundler.js +34 -6
  70. package/dist/compiler/compile.js +2234 -559
  71. package/dist/compiler/dom-binding-program.js +935 -0
  72. package/dist/compiler/dom-binding-request.js +57 -0
  73. package/dist/compiler/dom-bindings.js +2245 -0
  74. package/dist/compiler/hook-deps.js +26 -0
  75. package/dist/compiler/hydrate-boundaries.js +358 -15
  76. package/dist/compiler/index.d.ts +38 -1
  77. package/dist/compiler/index.js +1 -0
  78. package/dist/compiler/native-attribute-reads.js +127 -0
  79. package/dist/compiler/native-read-diagnostics.js +48 -9
  80. package/dist/compiler/native-read-types.js +55 -32
  81. package/dist/compiler/server-context.js +118 -0
  82. package/dist/compiler/signal-attempt-reads.js +479 -0
  83. package/dist/compiler/signal-declarations.js +557 -0
  84. package/dist/compiler/signal-start-reads.js +413 -0
  85. package/dist/compiler/slot-hooks.js +57 -10
  86. package/dist/compiler/template-ir.js +200 -0
  87. package/dist/compiler/typescript.d.ts +2 -0
  88. package/dist/compiler/typescript.js +2 -0
  89. package/dist/compiler/vite.d.ts +3 -1
  90. package/dist/compiler/vite.js +122 -4
  91. package/dist/compiler/volar.d.ts +6 -1
  92. package/dist/compiler/volar.js +674 -143
  93. package/dist/constants.d.ts +1 -0
  94. package/dist/constants.js +10 -0
  95. package/dist/css.d.ts +2 -5
  96. package/dist/css.js +2 -23
  97. package/dist/data-encoding.d.ts +9 -0
  98. package/dist/data-encoding.js +134 -0
  99. package/dist/dom-binding-classes.d.ts +15 -0
  100. package/dist/dom-binding-classes.js +129 -0
  101. package/dist/dom-binding-controls.d.ts +2 -0
  102. package/dist/dom-binding-controls.js +6 -0
  103. package/dist/dom-binding-handoff.d.ts +55 -0
  104. package/dist/dom-binding-handoff.js +62 -0
  105. package/dist/dom-binding-program.d.ts +300 -0
  106. package/dist/dom-binding-program.js +1625 -0
  107. package/dist/dom-binding-projections.d.ts +15 -0
  108. package/dist/dom-binding-projections.js +187 -0
  109. package/dist/dom-binding-protocol.d.ts +13 -0
  110. package/dist/dom-binding-protocol.js +88 -0
  111. package/dist/dom-binding-signals.d.ts +21 -0
  112. package/dist/dom-binding-signals.js +109 -0
  113. package/dist/dom-binding-styles.d.ts +17 -0
  114. package/dist/dom-binding-styles.js +272 -0
  115. package/dist/dom-bindings.d.ts +89 -0
  116. package/dist/dom-bindings.js +670 -0
  117. package/dist/dom-focused-move.d.ts +6 -0
  118. package/dist/dom-focused-move.js +42 -0
  119. package/dist/dom-tables.d.ts +1 -3
  120. package/dist/dom-tables.js +1 -91
  121. package/dist/error-codes.client.generated.d.ts +9 -0
  122. package/dist/error-codes.client.generated.js +33 -0
  123. package/dist/error-codes.server.generated.d.ts +5 -0
  124. package/dist/error-codes.server.generated.js +19 -0
  125. package/dist/hydration/control-capture.d.ts +62 -0
  126. package/dist/hydration/control-capture.js +223 -0
  127. package/dist/hydration/document-lifecycle.d.ts +23 -0
  128. package/dist/hydration/document-lifecycle.js +80 -0
  129. package/dist/hydration/event-capture.d.ts +20 -1
  130. package/dist/hydration/event-capture.js +128 -42
  131. package/dist/hydration/independent-island.d.ts +45 -0
  132. package/dist/hydration/independent-island.js +233 -0
  133. package/dist/hydration/index.d.ts +8 -1
  134. package/dist/hydration/index.js +55 -1
  135. package/dist/hydration/interaction-config.d.ts +5 -0
  136. package/dist/hydration/interaction-config.js +44 -1
  137. package/dist/hydration/stream-delivery.d.ts +32 -0
  138. package/dist/hydration/stream-delivery.js +333 -0
  139. package/dist/hydration/stream-receiver.d.ts +26 -0
  140. package/dist/hydration/stream-receiver.js +204 -0
  141. package/dist/hydration/stream-result-receiver.d.ts +70 -0
  142. package/dist/hydration/stream-result-receiver.js +246 -0
  143. package/dist/hydration/streamed-signals.d.ts +44 -0
  144. package/dist/hydration/streamed-signals.js +186 -0
  145. package/dist/hydration/types.d.ts +6 -0
  146. package/dist/hydration-markers.d.ts +7 -0
  147. package/dist/hydration-markers.js +10 -0
  148. package/dist/independent-hydration-protocol.d.ts +31 -0
  149. package/dist/independent-hydration-protocol.js +80 -0
  150. package/dist/index.d.ts +2 -0
  151. package/dist/index.js +4 -0
  152. package/dist/internal/signal-read.d.ts +1 -0
  153. package/dist/internal/signal-read.js +4 -0
  154. package/dist/jsx-runtime.d.ts +45 -6
  155. package/dist/public-types.d.ts +15 -1
  156. package/dist/runtime.d.ts +259 -21
  157. package/dist/runtime.js +2812 -220
  158. package/dist/runtime.server.d.ts +86 -6
  159. package/dist/runtime.server.js +712 -76
  160. package/dist/server/early-signals.d.ts +14 -0
  161. package/dist/server/early-signals.js +34 -0
  162. package/dist/server/index.d.ts +10 -2
  163. package/dist/server/index.js +48 -1
  164. package/dist/server/rpc-batch.d.ts +17 -0
  165. package/dist/server/rpc-batch.js +129 -0
  166. package/dist/server/rpc-stream.d.ts +9 -0
  167. package/dist/server/rpc-stream.js +125 -0
  168. package/dist/server/rpc.d.ts +5 -1
  169. package/dist/server/rpc.js +37 -13
  170. package/dist/server/signal-query-observation.d.ts +3 -0
  171. package/dist/server/signal-query-observation.js +134 -0
  172. package/dist/server/streamed-region.d.ts +15 -0
  173. package/dist/server/streamed-region.js +30 -0
  174. package/dist/server/streamed-signals.d.ts +45 -0
  175. package/dist/server/streamed-signals.js +488 -0
  176. package/dist/server-call.d.ts +41 -0
  177. package/dist/server-call.js +75 -0
  178. package/dist/server-rpc-batch-client.d.ts +7 -0
  179. package/dist/server-rpc-batch-client.js +119 -0
  180. package/dist/server-rpc-client.d.ts +3 -1
  181. package/dist/server-rpc-client.js +99 -27
  182. package/dist/server-rpc-protocol.d.ts +47 -0
  183. package/dist/server-rpc-protocol.js +109 -0
  184. package/dist/server-rpc-stream-client.d.ts +5 -0
  185. package/dist/server-rpc-stream-client.js +98 -0
  186. package/dist/signals/actions.d.ts +12 -0
  187. package/dist/signals/actions.js +466 -0
  188. package/dist/signals/client.d.ts +2 -0
  189. package/dist/signals/client.js +1 -0
  190. package/dist/signals/computations.d.ts +37 -0
  191. package/dist/signals/computations.js +455 -0
  192. package/dist/signals/control-binding.d.ts +31 -0
  193. package/dist/signals/control-binding.js +353 -0
  194. package/dist/signals/derived-facade.d.ts +3 -0
  195. package/dist/signals/derived-facade.js +25 -0
  196. package/dist/signals/document-owner.d.ts +10 -0
  197. package/dist/signals/document-owner.js +43 -0
  198. package/dist/signals/early-values.d.ts +24 -0
  199. package/dist/signals/early-values.js +124 -0
  200. package/dist/signals/encoding.d.ts +1 -3
  201. package/dist/signals/encoding.js +3 -93
  202. package/dist/signals/engine.d.ts +53 -4
  203. package/dist/signals/engine.js +275 -16
  204. package/dist/signals/errors.d.ts +7 -0
  205. package/dist/signals/errors.js +16 -0
  206. package/dist/signals/facade.d.ts +74 -0
  207. package/dist/signals/facade.js +452 -0
  208. package/dist/signals/graph.d.ts +50 -5
  209. package/dist/signals/graph.js +170 -19
  210. package/dist/signals/handle-protocol.d.ts +4 -0
  211. package/dist/signals/handle-protocol.js +11 -0
  212. package/dist/signals/index.d.ts +12 -3
  213. package/dist/signals/index.js +71 -2
  214. package/dist/signals/native-read-client.d.ts +3 -0
  215. package/dist/signals/native-read-client.js +10 -0
  216. package/dist/signals/owner-context.d.ts +22 -0
  217. package/dist/signals/owner-context.js +77 -0
  218. package/dist/signals/query-attempt-observer.d.ts +49 -0
  219. package/dist/signals/query-attempt-observer.js +41 -0
  220. package/dist/signals/query-facade.d.ts +3 -0
  221. package/dist/signals/query-facade.js +49 -0
  222. package/dist/signals/read-protocol.d.ts +32 -3
  223. package/dist/signals/read-protocol.js +26 -0
  224. package/dist/signals/requests.d.ts +38 -5
  225. package/dist/signals/requests.js +298 -15
  226. package/dist/signals/scalar-computations.d.ts +2 -0
  227. package/dist/signals/scalar-computations.js +60 -0
  228. package/dist/signals/server.d.ts +2 -0
  229. package/dist/signals/server.js +1 -0
  230. package/dist/signals/transition-candidate.d.ts +71 -0
  231. package/dist/signals/transition-candidate.js +557 -0
  232. package/dist/signals/transition-state.d.ts +51 -0
  233. package/dist/signals/transition-state.js +70 -0
  234. package/dist/signals/types.d.ts +95 -5
  235. package/dist/signals/types.js +20 -0
  236. package/dist/stream-protocol.d.ts +0 -5
  237. package/dist/stream-protocol.js +3 -0
  238. package/dist/streamed-signals-protocol.d.ts +60 -0
  239. package/dist/streamed-signals-protocol.js +130 -0
  240. package/dist/style-values.d.ts +3 -0
  241. package/dist/style-values.js +96 -0
  242. package/dist/version.js +1 -1
  243. package/package.json +37 -1
@@ -1,6 +1,7 @@
1
1
  import { trustHTML } from "./trusted-html.js";
2
2
  import { readNativeDomStyle, readNativeDomProps } from "./signals/read-protocol.js";
3
3
  import { resolveHookPath } from "./hook-slot-cache.js";
4
+ import { encodeBindingKey, isBindingOpenComment } from "./dom-binding-protocol.js";
4
5
  import {
5
6
  BLOCK_OPEN,
6
7
  BLOCK_CLOSE,
@@ -22,6 +23,9 @@ import {
22
23
  HYDRATE_ID_COUNT_ATTR,
23
24
  HYDRATE_STREAM_TOKEN_ATTR,
24
25
  HYDRATE_SEED_ATTR,
26
+ INDEPENDENT_HYDRATE_MANIFEST_ATTR,
27
+ HYDRATE_INDEPENDENT_ATTR,
28
+ SIGNAL_CONTROL_ATTR,
25
29
  STREAM_BOUNDARY_ATTR,
26
30
  STREAM_SEGMENT_ATTR,
27
31
  STREAM_SEED_ATTR,
@@ -38,6 +42,10 @@ import {
38
42
  SVG_ONLY_TAGS,
39
43
  VOID_ELEMENTS
40
44
  } from "./constants.js";
45
+ import {
46
+ createIndependentHydrateManifest,
47
+ serializeIndependentHydrateManifest
48
+ } from "./independent-hydration-protocol.js";
41
49
  import { hasOwnProp } from "./has-own.js";
42
50
  import { headOwnershipSuffix } from "./head-ownership.js";
43
51
  import { resourceHintWarning } from "./resource-hint-diagnostics.js";
@@ -54,6 +62,7 @@ import {
54
62
  invalidHostPropertiesWarning,
55
63
  unsupportedAttributeCoercionWarning
56
64
  } from "./host-property-diagnostics.js";
65
+ import { streamedSignalBootstrapJs } from "./server/early-signals.js";
57
66
  import {
58
67
  applyElementDefaultProps,
59
68
  childElementKey,
@@ -91,6 +100,76 @@ import {
91
100
  NATIVE_SIGNAL_FRESH_COMMENT,
92
101
  mergeNativeSeedReads
93
102
  } from "./signals/native-read-seeds.js";
103
+ import {
104
+ captureSignalOwner,
105
+ currentSignalOwner,
106
+ enterSynchronousSignalOwner,
107
+ retireSignalOwnerIdentity,
108
+ restoreSynchronousSignalOwner,
109
+ runWithSignalOwner
110
+ } from "./signals/owner-context.js";
111
+ import {
112
+ runWithServerSignalQueryAttemptObserver
113
+ } from "./signals/query-attempt-observer.js";
114
+ import {
115
+ SIGNAL_BINDING_IDENTITY,
116
+ SIGNAL_HANDLE
117
+ } from "./signals/types.js";
118
+ function isSignalHandle(value) {
119
+ return (typeof value === "object" || typeof value === "function") && value !== null && value[SIGNAL_HANDLE] === true;
120
+ }
121
+ function readSignalBinding(handle) {
122
+ if (RESOLVED !== null && !SERVER_SIGNAL_OWNER_ACTIVE) {
123
+ return withServerSignalBinding(() => handle.get());
124
+ }
125
+ return handle.get();
126
+ }
127
+ function withServerSignalBinding(read) {
128
+ ensureServerSignalOwner();
129
+ const owner = serverSignalOwner(FRAME);
130
+ const injection = RESOLVED.resourceOptions?.injection;
131
+ return runWithSignalOwner(
132
+ owner,
133
+ () => injection?.observeSignalAttempt === void 0 ? read() : runWithServerSignalQueryAttemptObserver(
134
+ owner,
135
+ (attempt) => injection.observeSignalAttempt(attempt, captureSignalOwner(owner)),
136
+ injection.createSignalAttemptObservations,
137
+ read
138
+ )
139
+ );
140
+ }
141
+ function isWritableSignal(value) {
142
+ return isSignalHandle(value) && value.kind === "signal" && typeof value.set === "function";
143
+ }
144
+ function ssrSignalValue(value) {
145
+ return isSignalHandle(value) ? readSignalBinding(value) : value;
146
+ }
147
+ const SSR_SIGNAL_CONTROL = /* @__PURE__ */ Symbol("octane.ssr-signal-control");
148
+ function isSsrSignalControlValue(value) {
149
+ return typeof value === "object" && value !== null && value[SSR_SIGNAL_CONTROL] === true;
150
+ }
151
+ function unwrapSsrSignalControlValue(value) {
152
+ return isSsrSignalControlValue(value) ? value.value : value;
153
+ }
154
+ function ssrSignalControlValue(value, site) {
155
+ if (!isWritableSignal(value)) return ssrSignalValue(value);
156
+ if (RESOLVED !== null && !SERVER_SIGNAL_OWNER_ACTIVE) {
157
+ return withServerSignalBinding(() => serverSignalControlValue(value, site));
158
+ }
159
+ return serverSignalControlValue(value, site);
160
+ }
161
+ function serverSignalControlValue(value, site) {
162
+ const owner = currentSignalOwner();
163
+ if (owner === null || !("documentOwner" in owner)) return value.get();
164
+ if (RESOLVED !== null) RESOLVED.hasSignalControls = true;
165
+ return {
166
+ [SSR_SIGNAL_CONTROL]: true,
167
+ value: value.get(),
168
+ site,
169
+ owner,
170
+ binding: value[SIGNAL_BINDING_IDENTITY]()
171
+ };
172
+ }
94
173
  const NATIVE_ARRAY_MAP = Array.prototype.map;
95
174
  const NATIVE_REFLECT_APPLY = Reflect.apply;
96
175
  const NATIVE_ARRAY_SPECIES_GETTER = Object.getOwnPropertyDescriptor(Array, Symbol.species)?.get;
@@ -184,6 +263,12 @@ const ACTIVE_PU_WARM_PLANS = [];
184
263
  let CURRENT_PU_WARM_CLAIMS = null;
185
264
  let ID_COUNTER = 0;
186
265
  let ID_PREFIX = "";
266
+ let SIGNAL_INSTANCE_PREFIX = "";
267
+ let SIGNAL_COMPONENT_INSTANCE_KEY = "";
268
+ let SERVER_SIGNAL_OWNER_ACTIVE = false;
269
+ let SIGNAL_CONTROL_SITE = "";
270
+ const EMPTY_SIGNAL_LIST_KEYS = [];
271
+ let SIGNAL_LIST_KEYS = EMPTY_SIGNAL_LIST_KEYS;
187
272
  function newStyleCollector() {
188
273
  const collector = /* @__PURE__ */ new Map();
189
274
  collector.replay = null;
@@ -406,6 +491,13 @@ const SCOPED_VALUE_PROPERTIES = {
406
491
  get() {
407
492
  return this[SCOPED_VALUE_RESOLVER]().children;
408
493
  }
494
+ },
495
+ __octaneInvocationSite: {
496
+ configurable: true,
497
+ enumerable: false,
498
+ get() {
499
+ return this[SCOPED_VALUE_RESOLVER]().__octaneInvocationSite;
500
+ }
409
501
  }
410
502
  };
411
503
  function restoreWritableScopedChildren(props, name, value) {
@@ -561,10 +653,15 @@ function scopedValueDescriptor(resolve) {
561
653
  Object.defineProperty(descriptor, "key", SCOPED_VALUE_PROPERTIES.key);
562
654
  Object.defineProperty(descriptor, "ref", SCOPED_VALUE_PROPERTIES.ref);
563
655
  Object.defineProperty(descriptor, "children", SCOPED_VALUE_PROPERTIES.children);
656
+ Object.defineProperty(
657
+ descriptor,
658
+ "__octaneInvocationSite",
659
+ SCOPED_VALUE_PROPERTIES.__octaneInvocationSite
660
+ );
564
661
  if (process.env.NODE_ENV !== "production") Object.freeze(descriptor);
565
662
  return descriptor;
566
663
  }
567
- function createScopedElement(type, props, readChildren) {
664
+ function createScopedElement(type, props, readChildren, invocationSite) {
568
665
  const src = props ?? null;
569
666
  const key = hasElementConfigKey(src) ? "" + src.key : null;
570
667
  const copiedProps = copyScopedElementConfig(type, src);
@@ -581,9 +678,9 @@ function createScopedElement(type, props, readChildren) {
581
678
  }
582
679
  return resolvedChildren;
583
680
  };
584
- return scopedElementDescriptor(type, copiedProps, key, children);
681
+ return scopedElementDescriptor(type, copiedProps, key, children, invocationSite);
585
682
  }
586
- function nativeCreateScopedElement(type, props, readChildren) {
683
+ function nativeCreateScopedElement(type, props, readChildren, invocationSite) {
587
684
  const src = props ?? null;
588
685
  const key = hasElementConfigKey(src) ? "" + src.key : null;
589
686
  const copiedProps = copyScopedElementConfig(type, src);
@@ -591,10 +688,11 @@ function nativeCreateScopedElement(type, props, readChildren) {
591
688
  type,
592
689
  copiedProps,
593
690
  key,
594
- createNativeServerScopedResolver(readChildren)
691
+ createNativeServerScopedResolver(readChildren),
692
+ invocationSite
595
693
  );
596
694
  }
597
- function scopedElementDescriptor(type, copiedProps, key, children) {
695
+ function scopedElementDescriptor(type, copiedProps, key, children, invocationSite) {
598
696
  setScopedChildrenResolver(copiedProps, children);
599
697
  SCOPED_ELEMENT_PROPS.add(copiedProps);
600
698
  const descriptor = {
@@ -604,31 +702,43 @@ function scopedElementDescriptor(type, copiedProps, key, children) {
604
702
  key,
605
703
  ref: copiedProps.ref !== void 0 ? copiedProps.ref : null
606
704
  };
705
+ if (invocationSite !== void 0) descriptor.__octaneInvocationSite = invocationSite;
607
706
  Object.defineProperty(descriptor, "children", SCOPED_CHILDREN_PROPERTY);
608
707
  setScopedChildrenResolver(descriptor, children);
609
708
  return finalizeElementDescriptor(descriptor);
610
709
  }
611
710
  function createElement(type, props, ...children) {
711
+ return createElementFromConfig(void 0, type, props, children);
712
+ }
713
+ function createElementAt(invocationSite, type, props, ...children) {
714
+ return createElementFromConfig(invocationSite, type, props, children);
715
+ }
716
+ function createElementFromConfig(invocationSite, type, props, children) {
612
717
  if (typeof type === "function" && isRendererContext(type)) {
613
718
  registerServerRendererContextProvider(renderServerContextProvider);
614
719
  }
615
720
  const src = props ?? null;
616
721
  const key = hasElementConfigKey(src) ? "" + src.key : null;
617
- let kids = children.length > 0 ? children.length === 1 ? children[0] : children : src?.children;
618
- if (children.length > 1) POSITIONAL_CHILDREN.add(children);
619
- if (children.length > 1 && process.env.NODE_ENV !== "production") Object.freeze(children);
722
+ const hasPositional = children !== void 0 && children.length > 0;
723
+ let kids = hasPositional ? children.length === 1 ? children[0] : children : src?.children;
724
+ if (children !== void 0 && children.length > 1) {
725
+ POSITIONAL_CHILDREN.add(children);
726
+ if (process.env.NODE_ENV !== "production") Object.freeze(children);
727
+ }
620
728
  const p = copyElementConfig(src);
621
- if (children.length > 0) p.children = kids;
729
+ if (hasPositional) p.children = kids;
622
730
  applyElementDefaultProps(type, p);
623
731
  kids = p.children;
624
- return finalizeElementDescriptor({
732
+ const descriptor = {
625
733
  $$kind: ELEMENT_TAG,
626
734
  type,
627
735
  props: p,
628
736
  key,
629
737
  ref: p.ref !== void 0 ? p.ref : null,
630
738
  children: kids ?? null
631
- });
739
+ };
740
+ if (invocationSite !== void 0) descriptor.__octaneInvocationSite = invocationSite;
741
+ return finalizeElementDescriptor(descriptor);
632
742
  }
633
743
  const POSITIONAL_CHILDREN = /* @__PURE__ */ new WeakSet();
634
744
  function positionalChildren(children) {
@@ -860,6 +970,8 @@ function cloneElement(element, config, ...children) {
860
970
  children: kids ?? null
861
971
  };
862
972
  }
973
+ if (element.__octaneInvocationSite !== void 0)
974
+ descriptor.__octaneInvocationSite = element.__octaneInvocationSite;
863
975
  return finalizeElementDescriptor(descriptor);
864
976
  }
865
977
  function cloneAndReplaceElementKey(element, key) {
@@ -1082,6 +1194,15 @@ function ssrHtml(html) {
1082
1194
  if (CURRENT_SCOPE === null) VT_SSR_HAS_RAW_HTML = false;
1083
1195
  return new RawServerHtml(html);
1084
1196
  }
1197
+ const BINDING_HTML_ROOT = /* @__PURE__ */ Symbol.for("octane.binding.html");
1198
+ function ssrBindingHtml(html, id) {
1199
+ const output = new ServerHtml(html);
1200
+ output[BINDING_HTML_ROOT] = "[b;" + id + ";root";
1201
+ return output;
1202
+ }
1203
+ function bindPresentationView(view, _id) {
1204
+ return markComponentFlags(view, COMPONENT_FLAG_BOUNDARY, view.name);
1205
+ }
1085
1206
  function serverComponentOutput(out, scope) {
1086
1207
  if (out == null) return "";
1087
1208
  if (typeof out === "string") return escapeHtml(out);
@@ -1119,21 +1240,53 @@ function ssrTextPre(v) {
1119
1240
  }
1120
1241
  function ssrComponentDescriptor(d, scope) {
1121
1242
  if (SCOPED_ELEMENT_PROPS.has(d.props)) {
1122
- return ssrComponent(scope, d.type, d.props);
1243
+ return ssrComponent(
1244
+ scope,
1245
+ d.type,
1246
+ d.props,
1247
+ void 0,
1248
+ d.key ?? void 0,
1249
+ void 0,
1250
+ d.__octaneInvocationSite
1251
+ );
1123
1252
  }
1124
1253
  const children = d.children;
1125
1254
  if (children == null || children === d.props?.children) {
1126
- return ssrComponent(scope, d.type, d.props);
1255
+ return ssrComponent(
1256
+ scope,
1257
+ d.type,
1258
+ d.props,
1259
+ void 0,
1260
+ d.key ?? void 0,
1261
+ void 0,
1262
+ d.__octaneInvocationSite
1263
+ );
1127
1264
  }
1128
- return ssrComponent(scope, d.type, {
1129
- ...d.props,
1130
- children
1131
- });
1265
+ return ssrComponent(
1266
+ scope,
1267
+ d.type,
1268
+ { ...d.props, children },
1269
+ void 0,
1270
+ d.key ?? void 0,
1271
+ void 0,
1272
+ d.__octaneInvocationSite
1273
+ );
1132
1274
  }
1133
1275
  function ssrChild(v, scope) {
1276
+ if (isSignalHandle(v)) {
1277
+ v = readSignalBinding(v);
1278
+ }
1134
1279
  if (probingDangerHtmlChild(v)) return "";
1135
1280
  return ssrChildValue(v, scope, true);
1136
1281
  }
1282
+ function ssrBindingChild(value, scope, marker) {
1283
+ const html = ssrChild(value, scope);
1284
+ if (!MARKERS) return html;
1285
+ const openingEnd = html.indexOf("-->");
1286
+ const framed = html.startsWith(BLOCK_OPEN) || html.startsWith("<!--") && openingEnd !== -1 && isBindingOpenComment(html.slice(4, openingEnd));
1287
+ const content = framed && html.endsWith(BLOCK_CLOSE) ? html.slice(openingEnd + 3, -BLOCK_CLOSE.length) : html;
1288
+ return ssrBindingBlock(content, marker);
1289
+ }
1137
1290
  function ssrChildValue(v, scope, includeKeyedSingle, selfMarkItem = false) {
1138
1291
  if (v !== null && typeof v === "object" && SERVER_HTML in v) {
1139
1292
  return v[SERVER_HTML];
@@ -1384,6 +1537,20 @@ function ssrDescriptorContent(v, scope) {
1384
1537
  function ssrBlock(content) {
1385
1538
  return MARKERS ? BLOCK_OPEN + content + BLOCK_CLOSE : String(content);
1386
1539
  }
1540
+ function ssrBindingBlock(content, marker) {
1541
+ return MARKERS ? "<!--" + marker + "-->" + content + BLOCK_CLOSE : String(content);
1542
+ }
1543
+ function ssrBindingKey(key, seen) {
1544
+ const encoded = encodeBindingKey(key);
1545
+ if (seen.has(encoded)) throw new TypeError(formatServerError(73));
1546
+ seen.add(encoded);
1547
+ return encoded;
1548
+ }
1549
+ function ssrBindingClass(receipt, values) {
1550
+ const snapshot = [normalizeClass(values[0]), values[1].map(normalizeClass)];
1551
+ const classes = [snapshot[0], ...snapshot[1]].filter(Boolean).join(" ");
1552
+ return ' class="' + escapeAttr(classes) + '" ' + receipt + '="' + escapeAttr(JSON.stringify(snapshot)) + '"';
1553
+ }
1387
1554
  function ssrFragmentMarker(open, _ref) {
1388
1555
  return MARKERS ? open ? "<!--frag-->" : "<!--/frag-->" : "";
1389
1556
  }
@@ -1466,31 +1633,48 @@ function withAsyncListScope(kind, fn) {
1466
1633
  function ssrControl(siteKey, fn) {
1467
1634
  const frame = FRAME;
1468
1635
  const occurrence = frame === null ? 0 : nextFrameOccurrence(frame, "@control:" + siteKey);
1469
- return withAsyncIdentity("control:" + siteKey, occurrence, fn);
1636
+ const previousSignalControl = SIGNAL_CONTROL_SITE;
1637
+ SIGNAL_CONTROL_SITE = siteKey;
1638
+ try {
1639
+ return withAsyncIdentity("control:" + siteKey, occurrence, fn);
1640
+ } finally {
1641
+ SIGNAL_CONTROL_SITE = previousSignalControl;
1642
+ }
1470
1643
  }
1471
- function enterAsyncArm(armKey) {
1644
+ function enterAsyncArm(armKey, mapped = false) {
1472
1645
  const previous = ASYNC_SCOPE;
1473
1646
  const frame = FRAME;
1474
1647
  const occurrence = frame === null ? 0 : nextFrameOccurrence(frame, "@arm-position:");
1475
1648
  const fallbackPosition = armKey !== null && (typeof armKey === "object" || typeof armKey === "function" || typeof armKey === "symbol") ? previous + "|@arm-position:" + occurrence : void 0;
1649
+ if (SERVER_SIGNAL_BINDINGS_POTENTIAL && SIGNAL_CONTROL_SITE.charCodeAt(0) === 102) {
1650
+ SIGNAL_LIST_KEYS = [
1651
+ ...SIGNAL_LIST_KEYS,
1652
+ signalIdentityKey(mapped ? "k" + String(armKey) : armKey)
1653
+ ];
1654
+ }
1476
1655
  ASYNC_SCOPE = previous + "|@arm:" + asyncIdentityKey(armKey, false, fallbackPosition);
1477
- return previous;
1478
1656
  }
1479
1657
  function ssrArm(armKey, fn) {
1480
- const previous = enterAsyncArm(armKey);
1658
+ const previous = ASYNC_SCOPE;
1659
+ const previousSignalKeys = SIGNAL_LIST_KEYS;
1481
1660
  try {
1661
+ enterAsyncArm(armKey);
1482
1662
  return fn();
1483
1663
  } finally {
1484
1664
  ASYNC_SCOPE = previous;
1665
+ SIGNAL_LIST_KEYS = previousSignalKeys;
1485
1666
  }
1486
1667
  }
1487
- function ssrForItem(armKey, fn, item, index, scope, block) {
1488
- const previous = enterAsyncArm(armKey);
1668
+ function ssrForItem(armKey, fn, item, index, scope, block, mapped = false) {
1669
+ const previous = ASYNC_SCOPE;
1670
+ const previousSignalKeys = SIGNAL_LIST_KEYS;
1489
1671
  try {
1672
+ enterAsyncArm(armKey, mapped);
1490
1673
  const html = index === void 0 ? fn(item, scope) : fn(item, index, scope);
1491
1674
  return block ? ssrBlock(html) : html;
1492
1675
  } finally {
1493
1676
  ASYNC_SCOPE = previous;
1677
+ SIGNAL_LIST_KEYS = previousSignalKeys;
1494
1678
  }
1495
1679
  }
1496
1680
  function ssrPortal() {
@@ -1899,14 +2083,32 @@ function ssrClass(sources) {
1899
2083
  }
1900
2084
  return found ? ssrAttr("class", value) : "";
1901
2085
  }
1902
- function ssrSnapshotSpread(obj) {
2086
+ function ssrSnapshotSpread(obj, controlSite, deferStyle = false) {
1903
2087
  if (obj == null) return null;
1904
2088
  const source = Object(obj);
1905
2089
  const snapshot = /* @__PURE__ */ Object.create(null);
1906
2090
  for (const key of Reflect.ownKeys(source)) {
1907
2091
  if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
1908
- const value = source[key];
1909
- if (typeof key === "string") snapshot[key] = value;
2092
+ let value = source[key];
2093
+ if (typeof key !== "string") continue;
2094
+ if (key === "style" && deferStyle) {
2095
+ snapshot[key] = value;
2096
+ continue;
2097
+ }
2098
+ if (controlSite !== void 0 && (key === "value" || key === "checked") && isWritableSignal(value)) {
2099
+ value = ssrSignalControlValue(value, controlSite);
2100
+ } else if (isSignalHandle(value)) value = readSignalBinding(value);
2101
+ else if (key === "style" && value !== null && typeof value === "object") {
2102
+ let style;
2103
+ for (const name of Object.keys(value)) {
2104
+ const current = value[name];
2105
+ if (!isSignalHandle(current)) continue;
2106
+ style ??= { ...value };
2107
+ style[name] = readSignalBinding(current);
2108
+ }
2109
+ if (style !== void 0) value = style;
2110
+ }
2111
+ snapshot[key] = value;
1910
2112
  }
1911
2113
  return snapshot;
1912
2114
  }
@@ -2031,24 +2233,48 @@ function ssrFormAuthoringDiagnostics(tag, sources) {
2031
2233
  return "";
2032
2234
  }
2033
2235
  function ssrValueAttr(v) {
2236
+ v = unwrapSsrSignalControlValue(v);
2034
2237
  if (v == null || typeof v === "function" || typeof v === "symbol") return "";
2035
2238
  return ' value="' + escapeAttr(typeof v === "string" ? v : String(v)) + '"';
2036
2239
  }
2037
2240
  function ssrCheckedAttr(v) {
2241
+ v = unwrapSsrSignalControlValue(v);
2038
2242
  return v == null || !v ? "" : " checked";
2039
2243
  }
2040
2244
  function ssrInputAttrs(sources) {
2041
2245
  const props = resolveFormControlSources(sources);
2042
2246
  if (process.env.NODE_ENV !== "production") {
2043
2247
  devValidateSsrFormProps("input", {
2044
- value: props.value,
2045
- defaultValue: props.defaultValue,
2046
- checked: props.checked,
2047
- defaultChecked: props.defaultChecked
2248
+ value: unwrapSsrSignalControlValue(props.value),
2249
+ defaultValue: unwrapSsrSignalControlValue(props.defaultValue),
2250
+ checked: unwrapSsrSignalControlValue(props.checked),
2251
+ defaultChecked: unwrapSsrSignalControlValue(props.defaultChecked)
2048
2252
  });
2049
2253
  }
2050
2254
  return ssrValueAttr(props.value ?? props.defaultValue) + ssrCheckedAttr(props.checked ?? props.defaultChecked);
2051
2255
  }
2256
+ function ssrSignalControlAttrs(sources) {
2257
+ const props = resolveFormControlSources(sources);
2258
+ const controls = [];
2259
+ let ownerKey;
2260
+ const record = (value, channel) => {
2261
+ if (!isSsrSignalControlValue(value)) return;
2262
+ const documentKey = value.owner.documentOwner.scopeKey;
2263
+ if (ownerKey !== void 0 && ownerKey !== documentKey) {
2264
+ throw new Error(formatServerError(68));
2265
+ }
2266
+ ownerKey = documentKey;
2267
+ controls.push([
2268
+ value.binding.scope === "document" ? "" : value.owner.instanceKey,
2269
+ value.binding.nodeKey,
2270
+ channel
2271
+ ]);
2272
+ };
2273
+ record(props.value, "value");
2274
+ record(props.checked, "checked");
2275
+ if (controls.length === 0) return "";
2276
+ return " " + SIGNAL_CONTROL_ATTR + '="' + escapeAttr(JSON.stringify([1, ownerKey, controls])) + '"';
2277
+ }
2052
2278
  function resolveFormControlSources(sources) {
2053
2279
  const resolved = {
2054
2280
  value: void 0,
@@ -2099,6 +2325,7 @@ function resolveFormControlSources(sources) {
2099
2325
  return resolved;
2100
2326
  }
2101
2327
  function ssrTextareaValue(v) {
2328
+ v = unwrapSsrSignalControlValue(v);
2102
2329
  if (v == null) return "";
2103
2330
  const s = escapeHtml(typeof v === "string" ? v : String(v));
2104
2331
  return s.charCodeAt(0) === 10 ? "\n" + s : s;
@@ -2107,8 +2334,8 @@ function ssrTextareaValueSources(sources) {
2107
2334
  const props = resolveFormControlSources(sources);
2108
2335
  if (process.env.NODE_ENV !== "production") {
2109
2336
  devValidateSsrFormProps("textarea", {
2110
- value: props.value,
2111
- defaultValue: props.defaultValue
2337
+ value: unwrapSsrSignalControlValue(props.value),
2338
+ defaultValue: unwrapSsrSignalControlValue(props.defaultValue)
2112
2339
  });
2113
2340
  }
2114
2341
  const value = props.value ?? props.defaultValue;
@@ -2120,6 +2347,8 @@ function ssrSelectAttrs(sources) {
2120
2347
  }
2121
2348
  const SELECT_STACK = [];
2122
2349
  function ssrSelectScope(value, defaultValue, multiple, children) {
2350
+ value = unwrapSsrSignalControlValue(value);
2351
+ defaultValue = unwrapSsrSignalControlValue(defaultValue);
2123
2352
  if (process.env.NODE_ENV !== "production") {
2124
2353
  devValidateSsrFormProps("select", { value, defaultValue, multiple });
2125
2354
  }
@@ -2478,10 +2707,96 @@ function replayUpdatedComponentBody(comp, props, scope, frame, hp, snapshot, war
2478
2707
  hp.occ = null;
2479
2708
  rewindComponentReplayState(snapshot, scope, frame);
2480
2709
  ACTIVE_PU_WARM_PLANS.length = warmPlanCheckpoint;
2481
- out = comp(props ?? {}, scope, void 0);
2710
+ out = invokeServerSignalComponent(comp, props, scope, serverSignalOwner(frame));
2482
2711
  } while (hp.update);
2483
2712
  return out;
2484
2713
  }
2714
+ function signalIdentityKey(value) {
2715
+ if (value === null) return "null";
2716
+ const kind = typeof value;
2717
+ return kind === "string" || kind === "number" || kind === "bigint" || kind === "boolean" ? kind.charCodeAt(0).toString(36) + ":" + String(value) : kind === "undefined" ? "u:" : "o:" + String(value);
2718
+ }
2719
+ function serverStructuralSignalInstanceKey(invocationSite, key) {
2720
+ return resolveServerSignalInstanceKey(SIGNAL_COMPONENT_INSTANCE_KEY) + JSON.stringify([
2721
+ invocationSite ?? "legacy",
2722
+ SIGNAL_LIST_KEYS,
2723
+ key != null ? signalIdentityKey(key) : ""
2724
+ ]);
2725
+ }
2726
+ function resolveServerSignalInstanceKey(identity) {
2727
+ if (typeof identity === "string") return identity;
2728
+ if (identity.signalInstanceKey !== void 0) return identity.signalInstanceKey;
2729
+ const pending = [];
2730
+ while (typeof identity !== "string") {
2731
+ if (identity.signalInstanceKey !== void 0) {
2732
+ identity = identity.signalInstanceKey;
2733
+ break;
2734
+ }
2735
+ pending.push(identity);
2736
+ identity = identity.signalParentKey;
2737
+ }
2738
+ for (let index = pending.length - 1; index >= 0; index--) {
2739
+ const frame = pending[index];
2740
+ identity += JSON.stringify([
2741
+ frame.signalInvocationSite ?? "legacy",
2742
+ frame.signalListKeys,
2743
+ frame.signalKey
2744
+ ]);
2745
+ frame.signalInstanceKey = identity;
2746
+ }
2747
+ return identity;
2748
+ }
2749
+ function serverSignalOwner(_frame) {
2750
+ const resolved = RESOLVED;
2751
+ if (resolved !== null && SERVER_SIGNAL_BINDINGS_ENABLED && resolved.signalOwner === void 0) {
2752
+ ensureServerSignalOwner();
2753
+ }
2754
+ if (resolved === null || resolved.signalOwner === void 0 || resolved.signalInstances === void 0)
2755
+ return;
2756
+ const instanceKey = resolveServerSignalInstanceKey(SIGNAL_COMPONENT_INSTANCE_KEY) || JSON.stringify([SIGNAL_INSTANCE_PREFIX, "root"]);
2757
+ let owner = resolved.signalInstances.get(instanceKey);
2758
+ if (owner === void 0) {
2759
+ owner = Object.freeze({
2760
+ scopeKey: resolved.signalOwner.scopeKey,
2761
+ documentOwner: resolved.signalOwner,
2762
+ instanceOwner: Object.freeze({}),
2763
+ instanceKey
2764
+ });
2765
+ resolved.signalInstances.set(instanceKey, owner);
2766
+ }
2767
+ return owner;
2768
+ }
2769
+ function ensureServerSignalOwner() {
2770
+ const resolved = RESOLVED;
2771
+ if (resolved.signalOwner !== void 0 && resolved.signalInstances !== void 0) return;
2772
+ const ambient = currentSignalOwner();
2773
+ resolved.signalOwner = ambient === null ? Object.freeze({ scopeKey: "octane:document" }) : isRendererSignalOwner(ambient) ? ambient.documentOwner : ambient;
2774
+ resolved.ownedSignalOwner = ambient === null;
2775
+ resolved.signalInstances = /* @__PURE__ */ new Map();
2776
+ }
2777
+ function invokeServerSignalComponent(comp, props, scope, owner) {
2778
+ if (owner === void 0) return comp(props ?? {}, scope, void 0);
2779
+ const invoke = () => {
2780
+ const previous = SERVER_SIGNAL_OWNER_ACTIVE;
2781
+ SERVER_SIGNAL_OWNER_ACTIVE = true;
2782
+ try {
2783
+ return comp(props ?? {}, scope, void 0);
2784
+ } finally {
2785
+ SERVER_SIGNAL_OWNER_ACTIVE = previous;
2786
+ }
2787
+ };
2788
+ const injection = RESOLVED?.resourceOptions?.injection;
2789
+ const observe = injection?.observeSignalAttempt;
2790
+ return runWithSignalOwner(
2791
+ owner,
2792
+ () => observe === void 0 ? invoke() : runWithServerSignalQueryAttemptObserver(
2793
+ owner,
2794
+ (attempt) => observe(attempt, captureSignalOwner(owner)),
2795
+ injection.createSignalAttemptObservations,
2796
+ invoke
2797
+ )
2798
+ );
2799
+ }
2485
2800
  function invokeComponentBody(comp, props, scope, frame) {
2486
2801
  const prevHP = HOOK_PASS;
2487
2802
  const hp = { hooks: null, occ: null, update: false };
@@ -2490,7 +2805,7 @@ function invokeComponentBody(comp, props, scope, frame) {
2490
2805
  HOOK_PASS = hp;
2491
2806
  try {
2492
2807
  ACTIVE_PU_WARM_PLANS.length = warmPlanCheckpoint;
2493
- let out = comp(props ?? {}, scope, void 0);
2808
+ let out = invokeServerSignalComponent(comp, props, scope, serverSignalOwner(frame));
2494
2809
  if (hp.update) {
2495
2810
  out = replayUpdatedComponentBody(comp, props, scope, frame, hp, snapshot, warmPlanCheckpoint);
2496
2811
  }
@@ -2502,14 +2817,25 @@ function invokeComponentBody(comp, props, scope, frame) {
2502
2817
  HOOK_PASS = prevHP;
2503
2818
  }
2504
2819
  }
2505
- function renderComponentFramed(comp, props, parent, frame, inherit) {
2506
- const prevScope = CURRENT_SCOPE;
2507
- const prevFrame = FRAME;
2508
- const prevComp = CURRENT_COMP;
2509
- const prevProps = CURRENT_PROPS;
2510
- const prevParent = CURRENT_PARENT_SCOPE;
2511
- const prevAsyncScope = ASYNC_SCOPE;
2512
- const parentScope = parent ?? prevScope;
2820
+ function captureServerComponentContext() {
2821
+ return {
2822
+ scope: CURRENT_SCOPE,
2823
+ frame: FRAME,
2824
+ comp: CURRENT_COMP,
2825
+ props: CURRENT_PROPS,
2826
+ parent: CURRENT_PARENT_SCOPE,
2827
+ asyncScope: ASYNC_SCOPE,
2828
+ signalInstance: SIGNAL_COMPONENT_INSTANCE_KEY,
2829
+ signalOwnerActive: SERVER_SIGNAL_OWNER_ACTIVE,
2830
+ signalControl: SIGNAL_CONTROL_SITE,
2831
+ signalListKeys: SIGNAL_LIST_KEYS,
2832
+ owner: void 0,
2833
+ previousOwner: void 0
2834
+ };
2835
+ }
2836
+ function renderComponentFramed(comp, props, parent, frame, inherit, instanceKey, bindingMarker) {
2837
+ const previous = captureServerComponentContext();
2838
+ const parentScope = parent ?? previous.scope;
2513
2839
  const scope = ssrScope(parentScope);
2514
2840
  CURRENT_SCOPE = scope;
2515
2841
  FRAME = frame;
@@ -2517,6 +2843,9 @@ function renderComponentFramed(comp, props, parent, frame, inherit) {
2517
2843
  CURRENT_PROPS = props;
2518
2844
  CURRENT_PARENT_SCOPE = parentScope;
2519
2845
  ASYNC_SCOPE = frame.asyncScope;
2846
+ if (instanceKey !== void 0) SIGNAL_COMPONENT_INSTANCE_KEY = instanceKey;
2847
+ SIGNAL_CONTROL_SITE = "";
2848
+ SIGNAL_LIST_KEYS = EMPTY_SIGNAL_LIST_KEYS;
2520
2849
  const nativeToken = NATIVE_READ_COLLECTOR === null ? -1 : beginActiveNativeReadScope(scope);
2521
2850
  let nativeCompleted = false;
2522
2851
  try {
@@ -2528,7 +2857,20 @@ function renderComponentFramed(comp, props, parent, frame, inherit) {
2528
2857
  HOOK_PASS = hookPass;
2529
2858
  try {
2530
2859
  ACTIVE_PU_WARM_PLANS.length = warmPlanCheckpoint;
2531
- out = comp(props ?? {}, scope, void 0);
2860
+ previous.owner = serverSignalOwner(frame);
2861
+ if (previous.owner === void 0) {
2862
+ out = comp(props ?? {}, scope, void 0);
2863
+ } else if (RESOLVED?.resourceOptions?.injection?.observeSignalAttempt !== void 0 || (previous.previousOwner = enterSynchronousSignalOwner(previous.owner)) === void 0) {
2864
+ out = invokeServerSignalComponent(comp, props, scope, previous.owner);
2865
+ } else {
2866
+ try {
2867
+ SERVER_SIGNAL_OWNER_ACTIVE = true;
2868
+ out = comp(props ?? {}, scope, void 0);
2869
+ } finally {
2870
+ SERVER_SIGNAL_OWNER_ACTIVE = previous.signalOwnerActive;
2871
+ restoreSynchronousSignalOwner(previous.previousOwner);
2872
+ }
2873
+ }
2532
2874
  if (hookPass.update) {
2533
2875
  out = replayUpdatedComponentBody(
2534
2876
  comp,
@@ -2546,22 +2888,29 @@ function renderComponentFramed(comp, props, parent, frame, inherit) {
2546
2888
  }
2547
2889
  const inner = serverComponentOutput(out, scope);
2548
2890
  nativeCompleted = true;
2549
- return MARKERS && !inherit ? BLOCK_OPEN + inner + BLOCK_CLOSE : inner;
2891
+ if (!MARKERS || inherit) return inner;
2892
+ const marker = bindingMarker ?? (out !== null && typeof out === "object" ? out[BINDING_HTML_ROOT] : void 0);
2893
+ return (marker === void 0 ? BLOCK_OPEN : "<!--" + marker + "-->") + inner + BLOCK_CLOSE;
2550
2894
  } catch (error) {
2551
2895
  throw normalizeThrownServerThenable(error);
2552
2896
  } finally {
2553
2897
  if (nativeToken >= 0) NATIVE_READ_COLLECTOR.endScope(nativeToken, nativeCompleted);
2554
- CURRENT_SCOPE = prevScope;
2555
- FRAME = prevFrame;
2556
- CURRENT_COMP = prevComp;
2557
- CURRENT_PROPS = prevProps;
2558
- CURRENT_PARENT_SCOPE = prevParent;
2559
- ASYNC_SCOPE = prevAsyncScope;
2560
- }
2561
- }
2562
- function ssrComponent(parent, comp, props, inherit, key, identityScoped) {
2898
+ CURRENT_SCOPE = previous.scope;
2899
+ FRAME = previous.frame;
2900
+ CURRENT_COMP = previous.comp;
2901
+ CURRENT_PROPS = previous.props;
2902
+ CURRENT_PARENT_SCOPE = previous.parent;
2903
+ ASYNC_SCOPE = previous.asyncScope;
2904
+ SIGNAL_COMPONENT_INSTANCE_KEY = previous.signalInstance;
2905
+ SERVER_SIGNAL_OWNER_ACTIVE = previous.signalOwnerActive;
2906
+ SIGNAL_CONTROL_SITE = previous.signalControl;
2907
+ SIGNAL_LIST_KEYS = previous.signalListKeys;
2908
+ }
2909
+ }
2910
+ function ssrComponent(parent, comp, props, inherit, key, identityScoped, invocationSite, bindingMarker) {
2563
2911
  const activity = comp === Activity;
2564
2912
  if (activity && key === void 0) key = props?.key;
2913
+ let signalInstanceKey = SERVER_SIGNAL_BINDINGS_ENABLED ? serverStructuralSignalInstanceKey(invocationSite, key) : void 0;
2565
2914
  const previousIdentityScope = ASYNC_SCOPE;
2566
2915
  if (identityScoped !== true) {
2567
2916
  ASYNC_SCOPE = previousIdentityScope + "|@component-type:" + asyncIdentityKey(comp, false);
@@ -2616,17 +2965,41 @@ function ssrComponent(parent, comp, props, inherit, key, identityScoped) {
2616
2965
  asyncScope: ASYNC_SCOPE,
2617
2966
  namespace: explicitNamespace ?? pf.namespace
2618
2967
  };
2619
- return renderComponentFramed(comp, props, parent, frame, inherit);
2968
+ if (signalInstanceKey === void 0 && SERVER_SIGNAL_BINDINGS_POTENTIAL) {
2969
+ frame.signalParentKey = SIGNAL_COMPONENT_INSTANCE_KEY;
2970
+ frame.signalInvocationSite = invocationSite;
2971
+ frame.signalListKeys = SIGNAL_LIST_KEYS;
2972
+ frame.signalKey = key != null ? signalIdentityKey(key) : "";
2973
+ signalInstanceKey = frame;
2974
+ }
2975
+ return renderComponentFramed(
2976
+ comp,
2977
+ props,
2978
+ parent,
2979
+ frame,
2980
+ inherit,
2981
+ signalInstanceKey,
2982
+ bindingMarker
2983
+ );
2620
2984
  } finally {
2621
2985
  if (identityScoped !== true) ASYNC_SCOPE = previousIdentityScope;
2622
2986
  }
2623
2987
  }
2624
2988
  let NEXT_COMPONENT_NAMESPACE = null;
2625
- function ssrComponentNS(parent, comp, props, namespace, inherit, key) {
2989
+ function ssrComponentNS(parent, comp, props, namespace, inherit, key, invocationSite, bindingMarker) {
2626
2990
  const previous = NEXT_COMPONENT_NAMESPACE;
2627
2991
  NEXT_COMPONENT_NAMESPACE = namespace;
2628
2992
  try {
2629
- return ssrComponent(parent, comp, props, inherit, key);
2993
+ return ssrComponent(
2994
+ parent,
2995
+ comp,
2996
+ props,
2997
+ inherit,
2998
+ key,
2999
+ void 0,
3000
+ invocationSite,
3001
+ bindingMarker
3002
+ );
2630
3003
  } finally {
2631
3004
  NEXT_COMPONENT_NAMESPACE = previous;
2632
3005
  }
@@ -2651,6 +3024,50 @@ function streamTokenForPendingHtml(html) {
2651
3024
  const stream = STREAM;
2652
3025
  return stream !== null && html.includes(STREAM_BOUNDARY_ATTR + '="' + stream.token + "-") ? stream.token : null;
2653
3026
  }
3027
+ function ssrIndependentHydrateSidecar(props, instanceId) {
3028
+ const independent = props.__independent;
3029
+ if (independent === void 0) return "";
3030
+ const registry = RESOLVED?.resourceOptions?.independentHydration;
3031
+ if (registry === void 0) {
3032
+ throw new Error(formatServerError(69));
3033
+ }
3034
+ const build = registry.resolve(independent.manifestTemplate.boundaryId);
3035
+ if (build === void 0) {
3036
+ throw new Error(formatServerError(70));
3037
+ }
3038
+ const manifest = createIndependentHydrateManifest(
3039
+ independent.manifestTemplate,
3040
+ independent.captures,
3041
+ instanceId,
3042
+ registry.buildId,
3043
+ build
3044
+ );
3045
+ return '<script type="application/json" ' + INDEPENDENT_HYDRATE_MANIFEST_ATTR + NONCE_ATTR + ">" + serializeIndependentHydrateManifest(manifest) + "</script>";
3046
+ }
3047
+ function withServerIndependentIdentity(prefix, idSeed, render) {
3048
+ const previous = SIGNAL_INSTANCE_PREFIX;
3049
+ const previousInstance = SIGNAL_COMPONENT_INSTANCE_KEY;
3050
+ const previousControl = SIGNAL_CONTROL_SITE;
3051
+ const previousListKeys = SIGNAL_LIST_KEYS;
3052
+ const previousIdPrefix = ID_PREFIX;
3053
+ const previousIdCounter = ID_COUNTER;
3054
+ SIGNAL_INSTANCE_PREFIX = prefix;
3055
+ SIGNAL_COMPONENT_INSTANCE_KEY = JSON.stringify([prefix, "root"]);
3056
+ SIGNAL_CONTROL_SITE = "";
3057
+ SIGNAL_LIST_KEYS = EMPTY_SIGNAL_LIST_KEYS;
3058
+ ID_PREFIX = prefix + "-";
3059
+ ID_COUNTER = idSeed;
3060
+ try {
3061
+ return render();
3062
+ } finally {
3063
+ SIGNAL_INSTANCE_PREFIX = previous;
3064
+ SIGNAL_COMPONENT_INSTANCE_KEY = previousInstance;
3065
+ SIGNAL_CONTROL_SITE = previousControl;
3066
+ SIGNAL_LIST_KEYS = previousListKeys;
3067
+ ID_PREFIX = previousIdPrefix;
3068
+ ID_COUNTER = previousIdCounter + ID_COUNTER - idSeed;
3069
+ }
3070
+ }
2654
3071
  function ssrHydrateAttrs(id, when, idCount, permanentStaticAncestor = false, streamToken = null) {
2655
3072
  const direct = typeof when !== "function" && when !== null ? when : null;
2656
3073
  let attrs = ssrAttr(HYDRATE_ID_ATTR, id, "div") + ssrAttr(
@@ -2708,7 +3125,8 @@ const PermanentStaticHydrate = /* @__PURE__ */ markComponentFlags(
2708
3125
  "PermanentStaticHydrate"
2709
3126
  );
2710
3127
  const hydrate = /* @__PURE__ */ markComponentFlags(
2711
- function Hydrate(props, scope) {
3128
+ function Hydrate(rawProps, scope) {
3129
+ const props = rawProps;
2712
3130
  const id = useId();
2713
3131
  return ssrHtml(
2714
3132
  withSsrElementContext(
@@ -2726,7 +3144,7 @@ const hydrate = /* @__PURE__ */ markComponentFlags(
2726
3144
  let children;
2727
3145
  let nativeReads = null;
2728
3146
  try {
2729
- children = ssrBlock(
3147
+ const renderChildren = () => ssrBlock(
2730
3148
  ssrTry(
2731
3149
  scope,
2732
3150
  "jsx-hydrate",
@@ -2736,6 +3154,11 @@ const hydrate = /* @__PURE__ */ markComponentFlags(
2736
3154
  "html"
2737
3155
  )
2738
3156
  );
3157
+ children = props.__independent === void 0 ? renderChildren() : withServerIndependentIdentity(
3158
+ id,
3159
+ props.__independent.manifestTemplate.idSeed,
3160
+ renderChildren
3161
+ );
2739
3162
  } finally {
2740
3163
  nativeReads = finishNativeSeedCapture(nativeCapture, previousNativeReads, false);
2741
3164
  }
@@ -2753,7 +3176,8 @@ const hydrate = /* @__PURE__ */ markComponentFlags(
2753
3176
  const seedSidecar = seedJson === null || seedJson === "[]" ? "" : '<script type="application/json" ' + HYDRATE_SEED_ATTR + NONCE_ATTR + ">" + seedJson + "</script>";
2754
3177
  const nativeSeeds = permanentStaticAncestor ? void 0 : NATIVE_READ_COLLECTOR?.serialize(nativeReads);
2755
3178
  const nativeSidecar = nativeSeeds === void 0 ? "" : serializeNativeSignalSeeds(nativeSeeds, NONCE_ATTR);
2756
- return "<div" + attrs + ">" + children + seedSidecar + nativeSidecar + "</div>";
3179
+ const independentSidecar = permanentStaticAncestor ? "" : ssrIndependentHydrateSidecar(props, id);
3180
+ return "<div" + attrs + (props.__independent === void 0 ? "" : " " + HYDRATE_INDEPENDENT_ATTR + '=""') + ">" + children + seedSidecar + nativeSidecar + independentSidecar + "</div>";
2757
3181
  }),
2758
3182
  "html"
2759
3183
  )
@@ -3227,7 +3651,8 @@ function normalizeThrownServerThenable(error) {
3227
3651
  comp: CURRENT_COMP,
3228
3652
  props: CURRENT_PROPS,
3229
3653
  parentScope: CURRENT_PARENT_SCOPE,
3230
- frame
3654
+ frame,
3655
+ signalInstanceKey: SIGNAL_COMPONENT_INSTANCE_KEY
3231
3656
  });
3232
3657
  }
3233
3658
  return SSR_SUSPENSE;
@@ -3499,7 +3924,8 @@ function use(usable, siteKey, directSite) {
3499
3924
  comp: CURRENT_COMP,
3500
3925
  props: CURRENT_PROPS,
3501
3926
  parentScope: CURRENT_PARENT_SCOPE,
3502
- frame
3927
+ frame,
3928
+ signalInstanceKey: SIGNAL_COMPONENT_INSTANCE_KEY
3503
3929
  });
3504
3930
  }
3505
3931
  throw SSR_SUSPENSE;
@@ -3666,7 +4092,8 @@ function puBatch(thenables, warm) {
3666
4092
  comp: CURRENT_COMP,
3667
4093
  props: CURRENT_PROPS,
3668
4094
  parentScope: CURRENT_PARENT_SCOPE,
3669
- frame
4095
+ frame,
4096
+ signalInstanceKey: SIGNAL_COMPONENT_INSTANCE_KEY
3670
4097
  });
3671
4098
  }
3672
4099
  throw SSR_SUSPENSE;
@@ -3830,7 +4257,8 @@ function lazy(load) {
3830
4257
  comp: CURRENT_COMP,
3831
4258
  props: CURRENT_PROPS,
3832
4259
  parentScope: CURRENT_PARENT_SCOPE,
3833
- frame
4260
+ frame,
4261
+ signalInstanceKey: SIGNAL_COMPONENT_INSTANCE_KEY
3834
4262
  });
3835
4263
  }
3836
4264
  throw SSR_SUSPENSE;
@@ -4316,9 +4744,26 @@ function serializeNativeSignalSeeds(signals, nonceAttr, attr = NATIVE_SIGNAL_SEE
4316
4744
  const json = JSON.stringify(signals).replace(/</g, "\\u003c");
4317
4745
  return '<script type="application/json" ' + attr + nonceAttr + ">" + json + "</script>";
4318
4746
  }
4747
+ let SERVER_SIGNAL_BINDINGS_ENABLED = false;
4748
+ let SERVER_SIGNAL_BINDINGS_POTENTIAL = false;
4749
+ function enableServerSignalBindings(abi = 1, potentialOnly = false) {
4750
+ if (abi !== 1) throw new TypeError(formatServerError(71));
4751
+ SERVER_SIGNAL_BINDINGS_POTENTIAL = true;
4752
+ if (!potentialOnly) SERVER_SIGNAL_BINDINGS_ENABLED = true;
4753
+ }
4754
+ function isRendererSignalOwner(owner) {
4755
+ return "documentOwner" in owner;
4756
+ }
4319
4757
  function newResolvedMap(resourceOptions) {
4320
4758
  const m = /* @__PURE__ */ new Map();
4321
4759
  if (resourceOptions !== void 0) m.resourceOptions = resourceOptions;
4760
+ if (SERVER_SIGNAL_BINDINGS_ENABLED || resourceOptions?.signalOwner !== void 0) {
4761
+ const ambient = currentSignalOwner();
4762
+ const configured = resourceOptions?.signalOwner ?? ambient;
4763
+ m.signalOwner = configured === void 0 || configured === null ? Object.freeze({ scopeKey: "octane:document" }) : isRendererSignalOwner(configured) ? configured.documentOwner : configured;
4764
+ m.ownedSignalOwner = configured === void 0 || configured === null;
4765
+ m.signalInstances = /* @__PURE__ */ new Map();
4766
+ }
4322
4767
  m.asyncIdentities = /* @__PURE__ */ new Map();
4323
4768
  m.asyncPositionIdentities = /* @__PURE__ */ new Map();
4324
4769
  m.nextAsyncIdentity = 0;
@@ -4362,6 +4807,13 @@ function releaseServerRenderResources(resolved) {
4362
4807
  }
4363
4808
  const resources = resolved.resources;
4364
4809
  resolved.resourceOptions = void 0;
4810
+ if (resolved.signalInstances !== void 0) {
4811
+ for (const owner of resolved.signalInstances.values()) retireSignalOwnerIdentity(owner);
4812
+ resolved.signalInstances.clear();
4813
+ }
4814
+ if (resolved.ownedSignalOwner && resolved.signalOwner !== void 0) {
4815
+ retireSignalOwnerIdentity(resolved.signalOwner);
4816
+ }
4365
4817
  if (resources !== void 0) resolved.resources = void 0;
4366
4818
  if (resources === void 0 || resources.finished) return;
4367
4819
  resources.finished = true;
@@ -4387,6 +4839,11 @@ function saveAmbient() {
4387
4839
  warmClaims: CURRENT_PU_WARM_CLAIMS,
4388
4840
  id: ID_COUNTER,
4389
4841
  idPrefix: ID_PREFIX,
4842
+ signalInstancePrefix: SIGNAL_INSTANCE_PREFIX,
4843
+ signalComponentInstanceKey: SIGNAL_COMPONENT_INSTANCE_KEY,
4844
+ signalOwnerActive: SERVER_SIGNAL_OWNER_ACTIVE,
4845
+ signalControlSite: SIGNAL_CONTROL_SITE,
4846
+ signalListKeys: SIGNAL_LIST_KEYS,
4390
4847
  css: CSS,
4391
4848
  nonceAttr: NONCE_ATTR,
4392
4849
  markers: MARKERS,
@@ -4440,6 +4897,11 @@ function restoreAmbient(a) {
4440
4897
  CURRENT_PU_WARM_CLAIMS = a.warmClaims;
4441
4898
  ID_COUNTER = a.id;
4442
4899
  ID_PREFIX = a.idPrefix;
4900
+ SIGNAL_INSTANCE_PREFIX = a.signalInstancePrefix;
4901
+ SIGNAL_COMPONENT_INSTANCE_KEY = a.signalComponentInstanceKey;
4902
+ SERVER_SIGNAL_OWNER_ACTIVE = a.signalOwnerActive;
4903
+ SIGNAL_CONTROL_SITE = a.signalControlSite;
4904
+ SIGNAL_LIST_KEYS = a.signalListKeys;
4443
4905
  CSS = a.css;
4444
4906
  NONCE_ATTR = a.nonceAttr;
4445
4907
  MARKERS = a.markers;
@@ -4480,6 +4942,11 @@ function runFullFramedPass(component, props, resolved, nonceAttr = "", identifie
4480
4942
  CURRENT_PU_WARM_CLAIMS = null;
4481
4943
  ID_COUNTER = 0;
4482
4944
  ID_PREFIX = identifierPrefix;
4945
+ SIGNAL_INSTANCE_PREFIX = identifierPrefix;
4946
+ SIGNAL_COMPONENT_INSTANCE_KEY = JSON.stringify([identifierPrefix, "root"]);
4947
+ SERVER_SIGNAL_OWNER_ACTIVE = false;
4948
+ SIGNAL_CONTROL_SITE = "";
4949
+ SIGNAL_LIST_KEYS = EMPTY_SIGNAL_LIST_KEYS;
4483
4950
  NONCE_ATTR = nonceAttr;
4484
4951
  ASYNC_SCOPE = "";
4485
4952
  MARKERS = markers;
@@ -4533,6 +5000,10 @@ function runFullFramedPass(component, props, resolved, nonceAttr = "", identifie
4533
5000
  try {
4534
5001
  const out = invokeComponentBody(component, props, root, FRAME);
4535
5002
  body = serverComponentOutput(out, root);
5003
+ if (markers && out !== null && typeof out === "object") {
5004
+ const marker = out[BINDING_HTML_ROOT];
5005
+ if (marker !== void 0) body = ssrBindingBlock(body, marker);
5006
+ }
4536
5007
  nativePassCompleted = true;
4537
5008
  } catch (err) {
4538
5009
  err = normalizeThrownServerThenable(err);
@@ -4577,7 +5048,8 @@ function runFullFramedPass(component, props, resolved, nonceAttr = "", identifie
4577
5048
  vtCandidates,
4578
5049
  rawHtml,
4579
5050
  cssEntries: cssMap,
4580
- sheets: headBuf.sheets
5051
+ sheets: headBuf.sheets,
5052
+ hasSignalControls: resolved.hasSignalControls === true
4581
5053
  };
4582
5054
  if (signals !== void 0) result.signals = signals;
4583
5055
  return result;
@@ -4592,6 +5064,11 @@ function runDiscoveryRound(jobs, resolved, identifierPrefix) {
4592
5064
  CURRENT_PU_WARM_CLAIMS = null;
4593
5065
  ID_COUNTER = 0;
4594
5066
  ID_PREFIX = identifierPrefix;
5067
+ SIGNAL_INSTANCE_PREFIX = identifierPrefix;
5068
+ SIGNAL_COMPONENT_INSTANCE_KEY = JSON.stringify([identifierPrefix, "root"]);
5069
+ SERVER_SIGNAL_OWNER_ACTIVE = false;
5070
+ SIGNAL_CONTROL_SITE = "";
5071
+ SIGNAL_LIST_KEYS = EMPTY_SIGNAL_LIST_KEYS;
4595
5072
  NONCE_ATTR = "";
4596
5073
  ASYNC_SCOPE = "";
4597
5074
  MARKERS = true;
@@ -4638,7 +5115,14 @@ function runDiscoveryRound(jobs, resolved, identifierPrefix) {
4638
5115
  namespace: void 0
4639
5116
  };
4640
5117
  try {
4641
- renderComponentFramed(job.comp, job.props, job.parentScope, frame);
5118
+ renderComponentFramed(
5119
+ job.comp,
5120
+ job.props,
5121
+ job.parentScope,
5122
+ frame,
5123
+ void 0,
5124
+ job.signalInstanceKey
5125
+ );
4642
5126
  } catch (err) {
4643
5127
  if (!ssrIsSuspense(err)) continue;
4644
5128
  }
@@ -4856,10 +5340,13 @@ async function runBuffered(component, props, options, nonceAttr, resolved) {
4856
5340
  if (resolved.pu.touched !== void 0) resolved.pu.touched = /* @__PURE__ */ new Set();
4857
5341
  }
4858
5342
  }
4859
- function passToResult(pass, nonceAttr, separateHead = false) {
5343
+ function passToResult(pass, nonceAttr, separateHead = false, independentHydration = false, externalSignalBootstrap = false) {
4860
5344
  let body = pass.body;
4861
5345
  if (pass.serial.length > 0) body += serializeSuspenseSeeds(pass.serial, nonceAttr);
4862
5346
  if (pass.signals !== void 0) body += serializeNativeSignalSeeds(pass.signals, nonceAttr);
5347
+ if (!externalSignalBootstrap && (pass.hasSignalControls || independentHydration)) {
5348
+ body += "<script " + STREAM_SCRIPT_ATTR + nonceAttr + ">" + streamedSignalBootstrapJs(independentHydration) + "</script>";
5349
+ }
4863
5350
  let result;
4864
5351
  if (separateHead) {
4865
5352
  result = {
@@ -4874,20 +5361,108 @@ function passToResult(pass, nonceAttr, separateHead = false) {
4874
5361
  if (pass.signals !== void 0) result.signals = pass.signals;
4875
5362
  return result;
4876
5363
  }
5364
+ async function collectBufferedInjection(injection, signal) {
5365
+ let revision = 0;
5366
+ let wake;
5367
+ let settled = false;
5368
+ let failed = false;
5369
+ let failure;
5370
+ const notify = () => {
5371
+ revision++;
5372
+ const resume = wake;
5373
+ wake = void 0;
5374
+ resume?.();
5375
+ };
5376
+ const unsubscribe = injection.subscribe(notify);
5377
+ signal?.addEventListener("abort", notify, { once: true });
5378
+ injection.done.then(
5379
+ () => {
5380
+ settled = true;
5381
+ notify();
5382
+ },
5383
+ (error) => {
5384
+ failed = true;
5385
+ failure = error;
5386
+ settled = true;
5387
+ notify();
5388
+ }
5389
+ );
5390
+ let html = "";
5391
+ try {
5392
+ injection.renderComplete?.();
5393
+ for (; ; ) {
5394
+ signal?.throwIfAborted();
5395
+ const chunk = injection.take();
5396
+ if (chunk !== "") {
5397
+ html += chunk;
5398
+ injection.accepted?.();
5399
+ continue;
5400
+ }
5401
+ if (settled) {
5402
+ if (failed) throw failure;
5403
+ return html;
5404
+ }
5405
+ const observed = revision;
5406
+ await new Promise((resolve) => {
5407
+ wake = resolve;
5408
+ if (settled || revision !== observed) {
5409
+ wake = void 0;
5410
+ resolve();
5411
+ }
5412
+ });
5413
+ }
5414
+ } finally {
5415
+ unsubscribe();
5416
+ signal?.removeEventListener("abort", notify);
5417
+ }
5418
+ }
5419
+ function insertBufferedInjection(pass, injection) {
5420
+ if (injection === "") return;
5421
+ const tailStart = documentTailStart(pass.body);
5422
+ pass.body = tailStart === -1 ? pass.body + injection : pass.body.slice(0, tailStart) + injection + pass.body.slice(tailStart);
5423
+ }
4877
5424
  async function prerender(entryComponent, props, options) {
4878
5425
  const component = typeof entryComponent === "function" ? entryComponent : renderEntryValue;
4879
5426
  if (typeof entryComponent !== "function") {
4880
5427
  options ??= props;
4881
5428
  props = { value: entryComponent };
4882
5429
  }
4883
- const nonceAttr = nonceAttrOf(options);
4884
- const resolved = newResolvedMap(options ?? null);
5430
+ const preparedOptions = needsAutomaticSignalInjection(options) ? await prepareAutomaticSignalInjection(options) : options;
5431
+ const injection = preparedOptions?.injection;
5432
+ const cancelRender = injection === void 0 ? void 0 : new AbortController();
5433
+ injection?.done.then(NOOP, (error) => cancelRender.abort(error));
5434
+ const renderOptions = cancelRender === void 0 ? preparedOptions : {
5435
+ ...preparedOptions,
5436
+ signal: preparedOptions?.signal === void 0 ? cancelRender.signal : AbortSignal.any([preparedOptions.signal, cancelRender.signal])
5437
+ };
5438
+ const nonceAttr = nonceAttrOf(renderOptions);
5439
+ const resolved = newResolvedMap(renderOptions ?? null);
4885
5440
  try {
5441
+ const pass = await runBuffered(component, props, renderOptions, nonceAttr, resolved);
5442
+ if (injection !== void 0) {
5443
+ try {
5444
+ insertBufferedInjection(
5445
+ pass,
5446
+ await collectBufferedInjection(injection, renderOptions?.signal)
5447
+ );
5448
+ } catch (error) {
5449
+ renderOptions?.onError?.(error);
5450
+ throw error;
5451
+ }
5452
+ }
4886
5453
  return passToResult(
4887
- await runBuffered(component, props, options, nonceAttr, resolved),
5454
+ pass,
4888
5455
  nonceAttr,
4889
- options?.headChannel === "separate"
5456
+ renderOptions?.headChannel === "separate",
5457
+ renderOptions?.independentHydration !== void 0,
5458
+ renderOptions?.earlySignalBootstrap === "external"
4890
5459
  );
5460
+ } catch (error) {
5461
+ try {
5462
+ injection?.cancel?.(error);
5463
+ } catch {
5464
+ }
5465
+ throw error;
4891
5466
  } finally {
4892
5467
  releaseServerRenderResources(resolved);
4893
5468
  }
@@ -5002,7 +5577,13 @@ function renderToString(entryComponent, props, options) {
5002
5577
  } finally {
5003
5578
  releaseServerRenderResources(resolved);
5004
5579
  }
5005
- return passToResult(pass, nonceAttr, options?.headChannel === "separate");
5580
+ return passToResult(
5581
+ pass,
5582
+ nonceAttr,
5583
+ options?.headChannel === "separate",
5584
+ options?.independentHydration !== void 0,
5585
+ options?.earlySignalBootstrap === "external"
5586
+ );
5006
5587
  }
5007
5588
  function renderToStaticMarkup(entryComponent, props, options) {
5008
5589
  const component = typeof entryComponent === "function" ? entryComponent : renderEntryValue;
@@ -5718,6 +6299,20 @@ function drain(){
5718
6299
  }
5719
6300
  })();`;
5720
6301
  }
6302
+ function needsAutomaticSignalInjection(options) {
6303
+ return options?.streamedSignals !== void 0 && options?.injection?.observeSignalAttempt === void 0;
6304
+ }
6305
+ async function prepareAutomaticSignalInjection(options) {
6306
+ const config = options.streamedSignals;
6307
+ const { createAutomaticStreamedSignalInjection } = await import("./server/streamed-signals.js");
6308
+ return {
6309
+ ...options,
6310
+ injection: createAutomaticStreamedSignalInjection(
6311
+ { ...config, nonce: options.nonce },
6312
+ options.injection
6313
+ )
6314
+ };
6315
+ }
5721
6316
  function withStream(stream, fn) {
5722
6317
  const prev = STREAM;
5723
6318
  STREAM = stream;
@@ -5897,7 +6492,14 @@ async function runStream(component, props, options, sink, resolved) {
5897
6492
  return;
5898
6493
  }
5899
6494
  if (!html) return;
5900
- return write(html, false, rememberUnaccepted);
6495
+ const written = write(html, false, rememberUnaccepted);
6496
+ if (written === void 0) {
6497
+ injection.accepted?.();
6498
+ return;
6499
+ }
6500
+ return written.then(() => {
6501
+ injection.accepted?.();
6502
+ });
5901
6503
  };
5902
6504
  const recoveryInjection = injection === void 0 ? void 0 : async () => {
5903
6505
  if (signal?.aborted) {
@@ -6097,11 +6699,18 @@ async function runStream(component, props, options, sink, resolved) {
6097
6699
  }
6098
6700
  if (pass.serial.length > 0) shell += serializeSuspenseSeeds(pass.serial, nonceAttr);
6099
6701
  if (pass.signals !== void 0) shell += serializeNativeSignalSeeds(pass.signals, nonceAttr);
6702
+ if (options?.earlySignalBootstrap !== "external" && (injection?.streamedRenderer === true || pass.hasSignalControls || options?.independentHydration !== void 0)) {
6703
+ shell += "<script " + STREAM_SCRIPT_ATTR + nonceAttr + ">" + streamedSignalBootstrapJs(options?.independentHydration !== void 0) + "</script>";
6704
+ }
6705
+ if (injection?.takeInitialSelections !== void 0) shell += injection.takeInitialSelections();
6100
6706
  const anyPending = stream.boundaries.size > 0;
6101
6707
  let sentViewTransitions = pass.vtCandidates;
6102
6708
  if (anyPending)
6103
6709
  shell += "<script " + STREAM_SCRIPT_ATTR + nonceAttr + ">" + streamRuntimeJs() + (sentViewTransitions ? streamViewTransitionRuntimeJs() : "") + "</script>";
6104
6710
  try {
6711
+ if (injection?.streamedRenderer === true || pass.hasSignalControls || options?.independentHydration !== void 0) {
6712
+ options?.onEarlyHydrationReady?.();
6713
+ }
6105
6714
  const shellWrite = write(pass.vtCandidates ? vtSsrStrip(shell, pass.rawHtml) : shell);
6106
6715
  if (shellWrite !== void 0) await shellWrite;
6107
6716
  } catch (err) {
@@ -6432,10 +7041,8 @@ function renderToPipeableStream(entryComponent, props, options) {
6432
7041
  finishEnd();
6433
7042
  };
6434
7043
  let started = false;
6435
- const startRender = () => {
6436
- if (started) return;
6437
- started = true;
6438
- const renderOptions = { ...options, signal: controller.signal };
7044
+ const beginRender = (preparedOptions) => {
7045
+ const renderOptions = { ...preparedOptions, signal: controller.signal };
6439
7046
  const resolved = newResolvedMap(renderOptions);
6440
7047
  void runStream(
6441
7048
  component,
@@ -6472,6 +7079,18 @@ function renderToPipeableStream(entryComponent, props, options) {
6472
7079
  flushEnd();
6473
7080
  });
6474
7081
  };
7082
+ const startRender = () => {
7083
+ if (started) return;
7084
+ started = true;
7085
+ if (needsAutomaticSignalInjection(options)) {
7086
+ void prepareAutomaticSignalInjection(options).then(beginRender, (error) => {
7087
+ shellFailure = { error };
7088
+ options?.onShellError?.(error);
7089
+ options?.onError?.(error);
7090
+ flushEnd();
7091
+ });
7092
+ } else beginRender(options);
7093
+ };
6475
7094
  queueMicrotask(startRender);
6476
7095
  return {
6477
7096
  pipe(dest) {
@@ -6508,6 +7127,11 @@ function renderToReadableStream(entryComponent, props, options) {
6508
7127
  options ??= props;
6509
7128
  props = { value: entryComponent };
6510
7129
  }
7130
+ if (needsAutomaticSignalInjection(options)) {
7131
+ return prepareAutomaticSignalInjection(options).then(
7132
+ (prepared) => renderToReadableStream(component, props, prepared)
7133
+ );
7134
+ }
6511
7135
  return new Promise((resolveShell, rejectShell) => {
6512
7136
  const encoder = new TextEncoder();
6513
7137
  const renderController = new AbortController();
@@ -6992,16 +7616,20 @@ export {
6992
7616
  addTransitionType,
6993
7617
  beginNativeReadScope,
6994
7618
  beginNativeReadWitness,
7619
+ bindPresentationView,
6995
7620
  callWithReceiver,
6996
7621
  cloneElement,
6997
7622
  createContext,
6998
7623
  createElement,
7624
+ createElementAt,
7625
+ createElementFromConfig,
6999
7626
  createHostedServerSession,
7000
7627
  createPortal,
7001
7628
  createScopedElement,
7002
7629
  createScopedValue,
7003
7630
  descriptorChildren,
7004
7631
  enableNativeReadCollection,
7632
+ enableServerSignalBindings,
7005
7633
  encodeAsyncIdentityString,
7006
7634
  endNativeReadScope,
7007
7635
  escapeAttr,
@@ -7054,6 +7682,11 @@ export {
7054
7682
  ssrArm,
7055
7683
  ssrAttr,
7056
7684
  ssrAttrs,
7685
+ ssrBindingBlock,
7686
+ ssrBindingChild,
7687
+ ssrBindingClass,
7688
+ ssrBindingHtml,
7689
+ ssrBindingKey,
7057
7690
  ssrBlock,
7058
7691
  ssrCheckedAttr,
7059
7692
  ssrChild,
@@ -7085,6 +7718,9 @@ export {
7085
7718
  ssrSelectAttrs,
7086
7719
  ssrSelectScope,
7087
7720
  ssrSelectScopeSources,
7721
+ ssrSignalControlAttrs,
7722
+ ssrSignalControlValue,
7723
+ ssrSignalValue,
7088
7724
  ssrSnapshotSpread,
7089
7725
  ssrSpread,
7090
7726
  ssrSpreadContent,