ripple 0.3.90 → 0.3.92

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.
@@ -0,0 +1,173 @@
1
+ import {
2
+ HYDRATION_START_PENDING,
3
+ HYDRATION_START_ERRORED,
4
+ HYDRATION_END,
5
+ STREAM_CHUNK_ATTR,
6
+ STREAM_HEAD_ATTR,
7
+ COMMENT_NODE,
8
+ } from '../../../constants.js';
9
+
10
+ /**
11
+ * Inline client runtime for streaming SSR, emitted once at the end of the
12
+ * shell chunk (only when the shell contains unresolved flush-unit slots).
13
+ *
14
+ * Exposes two globals:
15
+ * - `__RIPPLE_B__`: registry shared with the hydrating app. Before a unit's
16
+ * chunk arrives, the app may register `{ a(template, errored) }` for a slot
17
+ * it hydrated in the pending state; after a swap the runtime stores `1` to
18
+ * mark the slot done.
19
+ * - `__RIPPLE_S__(id, errored)`: called by each streamed chunk. Moves streamed
20
+ * head content into the document head, then either hands the chunk template
21
+ * to the registered boundary (post-hydration arrival) or swaps the fallback
22
+ * DOM directly (pre-hydration arrival) and retires the slot markers so the
23
+ * result is byte-identical to non-streamed SSR output.
24
+ *
25
+ * Authored as a real function; the wire form is derived with
26
+ * `Function.prototype.toString()`. The ripple package ships source, so dev
27
+ * serves this body as written — and when an application's production server
28
+ * bundle is minified (vite's `build.minify`), the minifier compresses this
29
+ * function like any other code and `toString()` yields the minified form.
30
+ * Marker shapes come in as arguments so `src/constants.js` stays the single
31
+ * source of truth.
32
+ *
33
+ * Constraints on the body: it must be fully self-contained (no closure over
34
+ * module scope — it is serialized), and its source must not contain the
35
+ * character sequences that terminate or escape an inline script element
36
+ * (a closing script tag, or HTML comment open/close sequences).
37
+ *
38
+ * @param {string} pending_prefix - comment data prefix of a pending slot ('[?')
39
+ * @param {string} errored_prefix - comment data prefix of an errored slot ('[!')
40
+ * @param {string} end_marker - comment data closing a marker pair (']')
41
+ * @param {string} chunk_attr - template attribute carrying a unit's content
42
+ * @param {string} head_attr - template attribute carrying a unit's head content
43
+ * @param {number} comment_node - Node.COMMENT_NODE
44
+ * @returns {void}
45
+ */
46
+ function stream_runtime(
47
+ pending_prefix,
48
+ errored_prefix,
49
+ end_marker,
50
+ chunk_attr,
51
+ head_attr,
52
+ comment_node,
53
+ ) {
54
+ var doc = document;
55
+ var registry = window.__RIPPLE_B__ || (window.__RIPPLE_B__ = {});
56
+
57
+ /**
58
+ * @param {number} id
59
+ * @param {number} [errored]
60
+ */
61
+ window.__RIPPLE_S__ = function (id, errored) {
62
+ var head_template = doc.querySelector('template[' + head_attr + '="' + id + '"]');
63
+ if (head_template) {
64
+ doc.head.appendChild(/** @type {HTMLTemplateElement} */ (head_template).content);
65
+ head_template.remove();
66
+ }
67
+
68
+ var template = /** @type {HTMLTemplateElement | null} */ (
69
+ doc.querySelector('template[' + chunk_attr + '="' + id + '"]')
70
+ );
71
+
72
+ function done() {
73
+ registry[id] = 1;
74
+ if (template) {
75
+ template.remove();
76
+ }
77
+ }
78
+
79
+ // post-hydration arrival: the boundary hydrated this slot in the
80
+ // pending state and registered an activator — hand the chunk over
81
+ var boundary = registry[id];
82
+ if (boundary && typeof boundary === 'object') {
83
+ registry[id] = 1;
84
+ boundary.a(template, errored);
85
+ if (template) {
86
+ template.remove();
87
+ }
88
+ return;
89
+ }
90
+
91
+ // pre-hydration arrival: find the slot's open comment ("[?" + id)
92
+ var walker = doc.createTreeWalker(doc.body || doc.documentElement, 128 /* SHOW_COMMENT */);
93
+ /** @type {Comment | null} */
94
+ var open = null;
95
+ var node;
96
+ while ((node = /** @type {Comment | null} */ (walker.nextNode()))) {
97
+ if (node.data === pending_prefix + id) {
98
+ open = node;
99
+ break;
100
+ }
101
+ }
102
+ if (!open) {
103
+ done();
104
+ return;
105
+ }
106
+
107
+ // find the matching close comment, depth-aware: any "["-prefixed
108
+ // comment opens a nested marker pair, end_marker closes one
109
+ var depth = 0;
110
+ /** @type {ChildNode | null} */
111
+ var close = null;
112
+ var current = open.nextSibling;
113
+ while (current) {
114
+ if (current.nodeType === comment_node) {
115
+ var data = /** @type {Comment} */ (current).data;
116
+ if (data === end_marker) {
117
+ if (depth === 0) {
118
+ close = current;
119
+ break;
120
+ }
121
+ depth--;
122
+ } else if (data.charCodeAt(0) === 91 /* '[' */) {
123
+ depth++;
124
+ }
125
+ }
126
+ current = current.nextSibling;
127
+ }
128
+ if (!close) {
129
+ done();
130
+ return;
131
+ }
132
+
133
+ // remove the fallback (and any leftover marker comments) in the slot
134
+ current = open.nextSibling;
135
+ while (current !== close) {
136
+ var next = /** @type {ChildNode} */ (current).nextSibling;
137
+ /** @type {ChildNode} */ (current).remove();
138
+ current = next;
139
+ }
140
+
141
+ if (errored) {
142
+ // leave the slot empty and mark it errored — the hydrating
143
+ // boundary routes the error envelope from here
144
+ open.data = errored_prefix + id;
145
+ } else {
146
+ // insert the streamed content and retire the slot markers, so the
147
+ // DOM matches non-streamed SSR exactly
148
+ if (template) {
149
+ close.before(template.content);
150
+ }
151
+ open.remove();
152
+ close.remove();
153
+ }
154
+ done();
155
+ };
156
+ }
157
+
158
+ export const STREAM_RUNTIME_SCRIPT =
159
+ '<script>(' +
160
+ stream_runtime.toString() +
161
+ ')(' +
162
+ JSON.stringify(HYDRATION_START_PENDING) +
163
+ ',' +
164
+ JSON.stringify(HYDRATION_START_ERRORED) +
165
+ ',' +
166
+ JSON.stringify(HYDRATION_END) +
167
+ ',' +
168
+ JSON.stringify(STREAM_CHUNK_ATTR) +
169
+ ',' +
170
+ JSON.stringify(STREAM_HEAD_ATTR) +
171
+ ',' +
172
+ String(COMMENT_NODE) +
173
+ ')</script>';
@@ -5,5 +5,5 @@
5
5
  * @returns {string}
6
6
  */
7
7
  export function get_track_async_script_id(hash) {
8
- return `__tsrx_ta_${hash}`;
8
+ return `__ripple_ta_${hash}`;
9
9
  }
@@ -0,0 +1,448 @@
1
+ // @ts-nocheck
2
+ import * as _$_ from 'ripple/internal/client';
3
+
4
+ var root = _$_.template(`<div class="resolved"><span class="value"> </span><button class="inc">inc</button></div>`, 0);
5
+ var root_4 = _$_.template(`<!><footer class="after-async">after-async</footer>`, 1, 2);
6
+ var root_3 = _$_.template(`<!>`, 1, 1);
7
+ var root_5 = _$_.template(`<p class="loading">loading...</p>`, 0);
8
+ var root_2 = _$_.template(`<span class="before">before</span><!><span class="sibling-after">sibling-after</span>`, 1, 3);
9
+ var root_1 = _$_.template(`<!>`, 1, 1);
10
+ var root_6 = _$_.template(`<p class="resolved"> </p>`, 0);
11
+ var root_9 = _$_.template(`<em class="caught"> </em>`, 0);
12
+ var root_8 = _$_.template(`<span class="before">before</span><!>`, 1, 2);
13
+ var root_7 = _$_.template(`<!>`, 1, 1);
14
+ var root_10 = _$_.template(`<p class="resolved"> </p>`, 0);
15
+ var root_11 = _$_.template(`<em class="caught"> </em>`, 0);
16
+ var root_12 = _$_.template(`<p class="loading">loading...</p>`, 0);
17
+ var root_13 = _$_.template(`<p class="resolved"> </p>`, 0);
18
+ var root_14 = _$_.template(`<p class="loading">loading...</p>`, 0);
19
+ var root_15 = _$_.template(`<section class="root-catch"> </section>`, 0);
20
+ var root_16 = _$_.template(`<p class="root-pending">root-loading</p>`, 0);
21
+ var root_19 = _$_.template(`<p class="head-content"> </p>`, 0);
22
+ var root_18 = _$_.template(`<!>`, 1, 1);
23
+ var root_17 = _$_.template(`<!>`, 1, 1);
24
+ var root_20 = _$_.template(`<p class="loading">loading...</p>`, 0);
25
+ var root_21 = _$_.template(`<p class="root-async"> </p>`, 0);
26
+ var root_22 = _$_.template(`<p class="outer"> </p>`, 0);
27
+ var root_23 = _$_.template(`<p class="inner"> </p>`, 0);
28
+ var root_26 = _$_.template(`<p class="inner-loading">inner-loading</p>`, 0);
29
+ var root_25 = _$_.template(`<!><!>`, 1, 2);
30
+ var root_24 = _$_.template(`<!>`, 1, 1);
31
+ var root_27 = _$_.template(`<p class="outer-loading">outer-loading</p>`, 0);
32
+
33
+ import { track, trackAsync } from 'ripple';
34
+
35
+ function make() {
36
+ let resolve = () => {};
37
+ let reject = () => {};
38
+
39
+ const promise = new Promise((res, rej) => {
40
+ resolve = res;
41
+ reject = rej;
42
+ });
43
+
44
+ return { promise, resolve, reject };
45
+ }
46
+
47
+ export const controls = {};
48
+
49
+ export function resetControls() {
50
+ var __block = _$_.scope();
51
+
52
+ controls.basic = make();
53
+ controls.catchOnly = make();
54
+ controls.rejects = make();
55
+ controls.noCatch = make();
56
+ controls.outer = make();
57
+ controls.inner = make();
58
+ controls.rootDirect = make();
59
+ controls.head = make();
60
+ }
61
+
62
+ resetControls();
63
+
64
+ function BasicContent() {
65
+ return _$_.tsrx_element((__anchor, __block) => {
66
+ let lazy = _$_.track_async(() => controls.basic.promise, __block, '703e438e');
67
+ let lazy_1 = _$_.track(0, __block, '928bce39');
68
+ var div = root();
69
+
70
+ {
71
+ var span = _$_.child(div);
72
+
73
+ {
74
+ var expression = _$_.child(span, true);
75
+
76
+ _$_.pop(span);
77
+ }
78
+
79
+ var button = _$_.sibling(span);
80
+
81
+ button.__click = () => _$_.update(lazy_1);
82
+ }
83
+
84
+ _$_.render(() => {
85
+ _$_.set_text(expression, lazy.value + ':' + lazy_1.value);
86
+ });
87
+
88
+ _$_.append(__anchor, div);
89
+ });
90
+ }
91
+
92
+ export function StreamPending() {
93
+ return _$_.tsrx_element((__anchor, __block) => {
94
+ var fragment = root_1();
95
+ var node_3 = _$_.first_child_frag(fragment);
96
+
97
+ _$_.expression(node_3, () => _$_.tsrx_element((__anchor, __block) => {
98
+ var fragment_1 = root_2();
99
+ var span_1 = _$_.first_child_frag(fragment_1);
100
+ var node = _$_.sibling(span_1);
101
+
102
+ _$_.try(
103
+ node,
104
+ (__anchor) => {
105
+ var fragment_2 = root_3();
106
+ var node_2 = _$_.first_child_frag(fragment_2);
107
+
108
+ _$_.expression(node_2, () => _$_.tsrx_element((__anchor, __block) => {
109
+ var fragment_3 = root_4();
110
+ var node_1 = _$_.first_child_frag(fragment_3);
111
+
112
+ _$_.render_component(BasicContent, node_1, {});
113
+ _$_.append(__anchor, fragment_3);
114
+ }));
115
+
116
+ _$_.append(__anchor, fragment_2);
117
+ },
118
+ null,
119
+ (__anchor) => {
120
+ var p = root_5();
121
+
122
+ _$_.append(__anchor, p);
123
+ }
124
+ );
125
+
126
+ _$_.append(__anchor, fragment_1);
127
+ }));
128
+
129
+ _$_.append(__anchor, fragment);
130
+ });
131
+ }
132
+
133
+ function CatchOnlyContent() {
134
+ return _$_.tsrx_element((__anchor, __block) => {
135
+ let lazy_2 = _$_.track_async(() => controls.catchOnly.promise, __block, '50f939c6');
136
+ var p_1 = root_6();
137
+
138
+ {
139
+ var expression_1 = _$_.child(p_1);
140
+
141
+ _$_.expression(expression_1, () => lazy_2.value);
142
+ _$_.pop(p_1);
143
+ }
144
+
145
+ _$_.append(__anchor, p_1);
146
+ });
147
+ }
148
+
149
+ export function StreamCatchOnly() {
150
+ return _$_.tsrx_element((__anchor, __block) => {
151
+ var fragment_4 = root_7();
152
+ var node_5 = _$_.first_child_frag(fragment_4);
153
+
154
+ _$_.expression(node_5, () => _$_.tsrx_element((__anchor, __block) => {
155
+ var fragment_5 = root_8();
156
+ var span_2 = _$_.first_child_frag(fragment_5);
157
+ var node_4 = _$_.sibling(span_2);
158
+
159
+ _$_.try(
160
+ node_4,
161
+ (__anchor) => {
162
+ _$_.render_component(CatchOnlyContent, __anchor, {});
163
+ },
164
+ (__anchor, e) => {
165
+ var em = root_9();
166
+
167
+ {
168
+ var expression_2 = _$_.child(em);
169
+
170
+ _$_.expression(expression_2, () => e.message);
171
+ _$_.pop(em);
172
+ }
173
+
174
+ _$_.append(__anchor, em);
175
+ }
176
+ );
177
+
178
+ _$_.append(__anchor, fragment_5);
179
+ }));
180
+
181
+ _$_.append(__anchor, fragment_4);
182
+ });
183
+ }
184
+
185
+ function RejectContent() {
186
+ return _$_.tsrx_element((__anchor, __block) => {
187
+ let lazy_3 = _$_.track_async(() => controls.rejects.promise, __block, '96452a54');
188
+ var p_2 = root_10();
189
+
190
+ {
191
+ var expression_3 = _$_.child(p_2);
192
+
193
+ _$_.expression(expression_3, () => lazy_3.value);
194
+ _$_.pop(p_2);
195
+ }
196
+
197
+ _$_.append(__anchor, p_2);
198
+ });
199
+ }
200
+
201
+ export function StreamRejects() {
202
+ return _$_.tsrx_element((__anchor, __block) => {
203
+ _$_.try(
204
+ __anchor,
205
+ (__anchor) => {
206
+ _$_.render_component(RejectContent, __anchor, {});
207
+ },
208
+ (__anchor, e) => {
209
+ var em_1 = root_11();
210
+
211
+ {
212
+ var expression_4 = _$_.child(em_1);
213
+
214
+ _$_.expression(expression_4, () => e.message);
215
+ _$_.pop(em_1);
216
+ }
217
+
218
+ _$_.append(__anchor, em_1);
219
+ },
220
+ (__anchor) => {
221
+ var p_3 = root_12();
222
+
223
+ _$_.append(__anchor, p_3);
224
+ },
225
+ true
226
+ );
227
+ });
228
+ }
229
+
230
+ function NoCatchContent() {
231
+ return _$_.tsrx_element((__anchor, __block) => {
232
+ let lazy_4 = _$_.track_async(() => controls.noCatch.promise, __block, '6baa716b');
233
+ var p_4 = root_13();
234
+
235
+ {
236
+ var expression_5 = _$_.child(p_4);
237
+
238
+ _$_.expression(expression_5, () => lazy_4.value);
239
+ _$_.pop(p_4);
240
+ }
241
+
242
+ _$_.append(__anchor, p_4);
243
+ });
244
+ }
245
+
246
+ export function StreamNoCatch() {
247
+ return _$_.tsrx_element((__anchor, __block) => {
248
+ _$_.try(
249
+ __anchor,
250
+ (__anchor) => {
251
+ _$_.render_component(NoCatchContent, __anchor, {});
252
+ },
253
+ null,
254
+ (__anchor) => {
255
+ var p_5 = root_14();
256
+
257
+ _$_.append(__anchor, p_5);
258
+ },
259
+ true
260
+ );
261
+ });
262
+ }
263
+
264
+ export function RootCatch({ error, reset }) {
265
+ return _$_.tsrx_element((__anchor, __block) => {
266
+ var section = root_15();
267
+
268
+ _$_.event('Click', section, reset);
269
+
270
+ {
271
+ var expression_6 = _$_.child(section);
272
+
273
+ _$_.expression(expression_6, () => error.message);
274
+ _$_.pop(section);
275
+ }
276
+
277
+ _$_.append(__anchor, section);
278
+ });
279
+ }
280
+
281
+ export function RootPending() {
282
+ return _$_.tsrx_element((__anchor, __block) => {
283
+ var p_6 = root_16();
284
+
285
+ _$_.append(__anchor, p_6);
286
+ });
287
+ }
288
+
289
+ function HeadContent() {
290
+ return _$_.tsrx_element((__anchor, __block) => {
291
+ let lazy_5 = _$_.track_async(() => controls.head.promise, __block, '9cd3c3cd');
292
+ var fragment_6 = root_17();
293
+ var node_7 = _$_.first_child_frag(fragment_6);
294
+
295
+ _$_.expression(node_7, () => _$_.tsrx_element((__anchor, __block) => {
296
+ {
297
+ var consequent = (__anchor) => {
298
+ var fragment_7 = root_18();
299
+ var node_6 = _$_.first_child_frag(fragment_7);
300
+
301
+ _$_.expression(node_6, () => _$_.tsrx_element((__anchor, __block) => {
302
+ var p_7 = root_19();
303
+
304
+ {
305
+ var expression_7 = _$_.child(p_7);
306
+
307
+ _$_.expression(expression_7, () => lazy_5.value);
308
+ _$_.pop(p_7);
309
+ }
310
+
311
+ _$_.head('e957a664', (__anchor) => {
312
+ _$_.render(() => {
313
+ _$_.document.title = 'title:' + lazy_5.value;
314
+ });
315
+ });
316
+
317
+ _$_.append(__anchor, p_7);
318
+ }));
319
+
320
+ _$_.append(__anchor, fragment_7);
321
+ };
322
+
323
+ _$_.if(
324
+ __anchor,
325
+ (__render) => {
326
+ if (lazy_5.value) __render(consequent);
327
+ },
328
+ true
329
+ );
330
+ }
331
+ }));
332
+
333
+ _$_.append(__anchor, fragment_6);
334
+ });
335
+ }
336
+
337
+ export function StreamHead() {
338
+ return _$_.tsrx_element((__anchor, __block) => {
339
+ _$_.try(
340
+ __anchor,
341
+ (__anchor) => {
342
+ _$_.render_component(HeadContent, __anchor, {});
343
+ },
344
+ null,
345
+ (__anchor) => {
346
+ var p_8 = root_20();
347
+
348
+ _$_.append(__anchor, p_8);
349
+ },
350
+ true
351
+ );
352
+ });
353
+ }
354
+
355
+ export function StreamRootDirect() {
356
+ return _$_.tsrx_element((__anchor, __block) => {
357
+ let lazy_6 = _$_.track_async(() => controls.rootDirect.promise, __block, 'bc9e61da');
358
+ var p_9 = root_21();
359
+
360
+ {
361
+ var expression_8 = _$_.child(p_9);
362
+
363
+ _$_.expression(expression_8, () => lazy_6.value);
364
+ _$_.pop(p_9);
365
+ }
366
+
367
+ _$_.append(__anchor, p_9);
368
+ });
369
+ }
370
+
371
+ function OuterContent() {
372
+ return _$_.tsrx_element((__anchor, __block) => {
373
+ let lazy_7 = _$_.track_async(() => controls.outer.promise, __block, '35931cce');
374
+ var p_10 = root_22();
375
+
376
+ {
377
+ var expression_9 = _$_.child(p_10);
378
+
379
+ _$_.expression(expression_9, () => lazy_7.value);
380
+ _$_.pop(p_10);
381
+ }
382
+
383
+ _$_.append(__anchor, p_10);
384
+ });
385
+ }
386
+
387
+ function InnerContent() {
388
+ return _$_.tsrx_element((__anchor, __block) => {
389
+ let lazy_8 = _$_.track_async(() => controls.inner.promise, __block, '6c7d38ed');
390
+ var p_11 = root_23();
391
+
392
+ {
393
+ var expression_10 = _$_.child(p_11);
394
+
395
+ _$_.expression(expression_10, () => lazy_8.value);
396
+ _$_.pop(p_11);
397
+ }
398
+
399
+ _$_.append(__anchor, p_11);
400
+ });
401
+ }
402
+
403
+ export function StreamNested() {
404
+ return _$_.tsrx_element((__anchor, __block) => {
405
+ _$_.try(
406
+ __anchor,
407
+ (__anchor) => {
408
+ var fragment_8 = root_24();
409
+ var node_10 = _$_.first_child_frag(fragment_8);
410
+
411
+ _$_.expression(node_10, () => _$_.tsrx_element((__anchor, __block) => {
412
+ var fragment_9 = root_25();
413
+ var node_8 = _$_.first_child_frag(fragment_9);
414
+
415
+ _$_.render_component(OuterContent, node_8, {});
416
+
417
+ var node_9 = _$_.sibling(node_8);
418
+
419
+ _$_.try(
420
+ node_9,
421
+ (__anchor) => {
422
+ _$_.render_component(InnerContent, __anchor, {});
423
+ },
424
+ null,
425
+ (__anchor) => {
426
+ var p_12 = root_26();
427
+
428
+ _$_.append(__anchor, p_12);
429
+ }
430
+ );
431
+
432
+ _$_.append(__anchor, fragment_9);
433
+ }));
434
+
435
+ _$_.append(__anchor, fragment_8);
436
+ },
437
+ null,
438
+ (__anchor) => {
439
+ var p_13 = root_27();
440
+
441
+ _$_.append(__anchor, p_13);
442
+ },
443
+ true
444
+ );
445
+ });
446
+ }
447
+
448
+ _$_.delegate(['click']);