ripple 0.4.2 → 0.4.3
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/CHANGELOG.md +107 -0
- package/package.json +9 -3
- package/src/jsx-runtime.d.ts +2 -1
- package/src/runtime/array.js +15 -9
- package/src/runtime/index-client.js +25 -7
- package/src/runtime/index-server.js +1 -0
- package/src/runtime/internal/client/attributes.js +313 -0
- package/src/runtime/internal/client/blocks.js +4 -14
- package/src/runtime/internal/client/component.js +2 -5
- package/src/runtime/internal/client/composite.js +14 -6
- package/src/runtime/internal/client/constants.js +6 -6
- package/src/runtime/internal/client/context.js +3 -2
- package/src/runtime/internal/client/css.js +11 -26
- package/src/runtime/internal/client/errors.js +188 -0
- package/src/runtime/internal/client/events.js +79 -34
- package/src/runtime/internal/client/expression.js +21 -116
- package/src/runtime/internal/client/for.js +108 -232
- package/src/runtime/internal/client/head.js +4 -3
- package/src/runtime/internal/client/html.js +5 -3
- package/src/runtime/internal/client/hydrate.js +484 -0
- package/src/runtime/internal/client/hydration-enabled.js +7 -0
- package/src/runtime/internal/client/hydration.js +16 -81
- package/src/runtime/internal/client/if.js +13 -9
- package/src/runtime/internal/client/index.js +14 -6
- package/src/runtime/internal/client/operations.js +11 -7
- package/src/runtime/internal/client/portal.js +3 -2
- package/src/runtime/internal/client/render.js +42 -325
- package/src/runtime/internal/client/root-boundary-enabled.js +7 -0
- package/src/runtime/internal/client/runtime.js +87 -363
- package/src/runtime/internal/client/template-ns.js +47 -0
- package/src/runtime/internal/client/template.js +63 -140
- package/src/runtime/internal/client/track-async.js +356 -0
- package/src/runtime/internal/client/try.js +133 -319
- package/src/runtime/internal/client/types.d.ts +48 -24
- package/src/runtime/internal/server/index.js +31 -29
- package/src/runtime/internal/server/prerender.js +27 -0
- package/src/server/index.js +1 -0
- package/src/utils/class-name.js +28 -0
- package/tests/client/basic/basic.errors.test.tsrx +3 -3
- package/tests/client/compiler/__snapshots__/compiler.typescript.test.tsrx.snap +0 -2
- package/tests/client/compiler/compiler.basic.test.tsrx +2 -2
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +3 -3
- package/tests/client/composite/composite.props.test.tsrx +10 -10
- package/tests/client/derived-release.test.tsrx +3 -3
- package/tests/client/for-item.test.tsrx +39 -0
- package/tests/client/for-selector.test.tsrx +95 -0
- package/tests/hydration/compiled/client/basic.js +87 -87
- package/tests/hydration/compiled/client/composite.js +5 -5
- package/tests/hydration/compiled/client/events.js +40 -48
- package/tests/hydration/compiled/client/for.js +162 -181
- package/tests/hydration/compiled/client/fragment-cursor.js +521 -289
- package/tests/hydration/compiled/client/head.js +22 -22
- package/tests/hydration/compiled/client/hmr.js +4 -4
- package/tests/hydration/compiled/client/html-in-template.js +5 -5
- package/tests/hydration/compiled/client/html.js +152 -162
- package/tests/hydration/compiled/client/if-children.js +58 -53
- package/tests/hydration/compiled/client/if-fragment-controlflow.js +39 -39
- package/tests/hydration/compiled/client/if.js +26 -26
- package/tests/hydration/compiled/client/mixed-control-flow.js +56 -68
- package/tests/hydration/compiled/client/nested-control-flow.js +139 -271
- package/tests/hydration/compiled/client/portal.js +10 -10
- package/tests/hydration/compiled/client/reactivity.js +29 -29
- package/tests/hydration/compiled/client/return.js +2 -2
- package/tests/hydration/compiled/client/streaming.js +33 -35
- package/tests/hydration/compiled/client/switch.js +25 -25
- package/tests/hydration/compiled/client/track-async-serialization.js +41 -41
- package/tests/hydration/compiled/client/try.js +15 -15
- package/tests/hydration/compiled/client/typed-text.js +7 -7
- package/tests/hydration/compiled/server/basic.js +6 -6
- package/tests/hydration/compiled/server/events.js +8 -8
- package/tests/hydration/compiled/server/for.js +22 -22
- package/tests/hydration/compiled/server/fragment-cursor.js +188 -52
- package/tests/hydration/compiled/server/head.js +6 -6
- package/tests/hydration/compiled/server/hmr.js +1 -1
- package/tests/hydration/compiled/server/html.js +1 -1
- package/tests/hydration/compiled/server/if-children.js +9 -9
- package/tests/hydration/compiled/server/if.js +5 -5
- package/tests/hydration/compiled/server/mixed-control-flow.js +4 -4
- package/tests/hydration/compiled/server/portal.js +1 -1
- package/tests/hydration/compiled/server/reactivity.js +9 -9
- package/tests/hydration/compiled/server/streaming.js +9 -9
- package/tests/hydration/compiled/server/switch.js +4 -4
- package/tests/hydration/compiled/server/track-async-serialization.js +16 -16
- package/tests/hydration/compiled/server/try.js +4 -4
- package/tests/hydration/compiled/server/typed-text.js +1 -1
- package/tests/hydration/components/fragment-cursor.tsrx +60 -0
- package/tests/hydration/components/track-async-serialization.tsrx +2 -2
- package/tests/hydration/fragment-cursor.test.js +34 -1
- package/tests/hydration/track-async-serialization.test.js +1 -1
- package/tests/server/basic.components.test.tsrx +3 -3
- package/tests/server/track-async-serialization.test.tsrx +6 -6
- package/tests/utils/tracked-types.test.js +3 -3
- package/types/index.d.ts +8 -8
- package/types/server.d.ts +17 -0
|
@@ -6,9 +6,10 @@ import { BRANCH_BLOCK, IF_BLOCK, UNINITIALIZED } from './constants.js';
|
|
|
6
6
|
import { create_text, get_next_sibling } from './operations.js';
|
|
7
7
|
import { assign_nodes } from './template.js';
|
|
8
8
|
import { active_block } from './runtime.js';
|
|
9
|
-
import { hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
|
|
10
|
-
import { COMMENT_NODE,
|
|
9
|
+
import { H, hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
|
|
10
|
+
import { COMMENT_NODE, HYDRATION_START, TEXT_NODE } from '../../../constants.js';
|
|
11
11
|
import { is_tsrx_element, TSRX_ELEMENT } from '../../element.js';
|
|
12
|
+
import { HYDRATION } from 'ripple/internal/client/hydration-enabled';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Finds the nearest enclosing block that owns a DOM range (a branch or an if
|
|
@@ -58,7 +59,7 @@ export function render_value(value, anchor, block) {
|
|
|
58
59
|
* @returns {void}
|
|
59
60
|
*/
|
|
60
61
|
function render_tsrx_collection(value, anchor, block) {
|
|
61
|
-
if (hydrating) {
|
|
62
|
+
if (HYDRATION && hydrating) {
|
|
62
63
|
assign_nodes(/** @type {Node} */ (hydrate_node ?? anchor), anchor);
|
|
63
64
|
render_tsrx_collection_items(value, anchor, block);
|
|
64
65
|
return;
|
|
@@ -133,61 +134,15 @@ function render_tsrx_element(value, anchor, block) {
|
|
|
133
134
|
* @returns {void}
|
|
134
135
|
*/
|
|
135
136
|
function render_tsrx_collection_text(value, anchor, assign = false) {
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
insert_before(anchor, text);
|
|
139
|
-
if (assign) {
|
|
140
|
-
assign_nodes(text, text);
|
|
141
|
-
}
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
var node = hydrate_node;
|
|
146
|
-
|
|
147
|
-
if (node?.nodeType === COMMENT_NODE && /** @type {Comment} */ (node).data === HYDRATION_START) {
|
|
148
|
-
node = get_next_sibling(node);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (node?.nodeType === TEXT_NODE) {
|
|
152
|
-
var current_value = /** @type {Text} */ (node).nodeValue ?? '';
|
|
153
|
-
|
|
154
|
-
if (current_value !== value) {
|
|
155
|
-
/** @type {Text} */ (node).nodeValue = value;
|
|
156
|
-
|
|
157
|
-
if (current_value.startsWith(value)) {
|
|
158
|
-
var remaining = current_value.slice(value.length);
|
|
159
|
-
|
|
160
|
-
if (remaining !== '') {
|
|
161
|
-
var remaining_text = create_text(remaining);
|
|
162
|
-
/** @type {ChildNode} */ (node).after(remaining_text);
|
|
163
|
-
if (assign) {
|
|
164
|
-
assign_nodes(node, node);
|
|
165
|
-
}
|
|
166
|
-
set_hydrate_node(remaining_text);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (assign) {
|
|
173
|
-
assign_nodes(node, node);
|
|
174
|
-
}
|
|
175
|
-
set_hydrate_node(get_next_sibling(node) ?? anchor);
|
|
137
|
+
if (HYDRATION && hydrating) {
|
|
138
|
+
/** @type {import('./hydrate.js').HydrationRuntime} */ (H).x(value, anchor, assign);
|
|
176
139
|
return;
|
|
177
140
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (node !== null && node !== anchor) {
|
|
182
|
-
/** @type {ChildNode} */ (node).before(new_text);
|
|
183
|
-
} else {
|
|
184
|
-
anchor.before(new_text);
|
|
185
|
-
}
|
|
186
|
-
|
|
141
|
+
var text = create_text(value);
|
|
142
|
+
insert_before(anchor, text);
|
|
187
143
|
if (assign) {
|
|
188
|
-
assign_nodes(
|
|
144
|
+
assign_nodes(text, text);
|
|
189
145
|
}
|
|
190
|
-
set_hydrate_node(node ?? anchor);
|
|
191
146
|
}
|
|
192
147
|
|
|
193
148
|
/**
|
|
@@ -250,10 +205,13 @@ function run_expression(s) {
|
|
|
250
205
|
var anchor = s.a;
|
|
251
206
|
var type = typeof next_value;
|
|
252
207
|
var is_hydration_marker =
|
|
253
|
-
|
|
208
|
+
HYDRATION &&
|
|
209
|
+
hydrating &&
|
|
210
|
+
s.n === COMMENT_NODE &&
|
|
211
|
+
/** @type {Comment} */ (anchor).data === HYDRATION_START;
|
|
254
212
|
|
|
255
213
|
if (is_hydration_marker) {
|
|
256
|
-
s.m ??=
|
|
214
|
+
s.m ??= /** @type {import('./hydrate.js').HydrationRuntime} */ (H).e(anchor);
|
|
257
215
|
}
|
|
258
216
|
|
|
259
217
|
var end = s.m;
|
|
@@ -282,7 +240,7 @@ function run_expression(s) {
|
|
|
282
240
|
restore_parent_start(s);
|
|
283
241
|
}
|
|
284
242
|
|
|
285
|
-
if (end !== null && (s.i || !hydrating)) {
|
|
243
|
+
if (end !== null && (s.i || !(HYDRATION && hydrating))) {
|
|
286
244
|
clear_expression_range(anchor, end);
|
|
287
245
|
}
|
|
288
246
|
|
|
@@ -357,7 +315,10 @@ function run_expression(s) {
|
|
|
357
315
|
}
|
|
358
316
|
|
|
359
317
|
if (is_hydration_marker) {
|
|
360
|
-
var text = (s.t =
|
|
318
|
+
var text = (s.t = /** @type {import('./hydrate.js').HydrationRuntime} */ (H).h(
|
|
319
|
+
anchor,
|
|
320
|
+
/** @type {Comment} */ (end),
|
|
321
|
+
));
|
|
361
322
|
|
|
362
323
|
if (next_text === '') {
|
|
363
324
|
if (text !== null) {
|
|
@@ -408,68 +369,12 @@ function restore_parent_start(s) {
|
|
|
408
369
|
}
|
|
409
370
|
}
|
|
410
371
|
|
|
411
|
-
/**
|
|
412
|
-
* @param {Node} anchor
|
|
413
|
-
* @returns {Comment}
|
|
414
|
-
*/
|
|
415
|
-
function ensure_expression_end(anchor) {
|
|
416
|
-
if (hydrating) {
|
|
417
|
-
/** @type {Node | null} */
|
|
418
|
-
var current = get_next_sibling(anchor);
|
|
419
|
-
var depth = 0;
|
|
420
|
-
|
|
421
|
-
while (current !== null) {
|
|
422
|
-
if (current.nodeType === COMMENT_NODE) {
|
|
423
|
-
var data = /** @type {Comment} */ (current).data;
|
|
424
|
-
|
|
425
|
-
if (data === HYDRATION_START) {
|
|
426
|
-
depth += 1;
|
|
427
|
-
} else if (data === HYDRATION_END) {
|
|
428
|
-
if (depth === 0) {
|
|
429
|
-
return /** @type {Comment} */ (current);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
depth -= 1;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
current = get_next_sibling(current);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
throw new Error('Hydration mismatch: expected end marker for expression block');
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
var end = document.createComment(HYDRATION_END);
|
|
443
|
-
/** @type {ChildNode} */ (anchor).after(end);
|
|
444
|
-
return end;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* @param {Node} anchor
|
|
449
|
-
* @param {Node} end
|
|
450
|
-
* @returns {Text | null}
|
|
451
|
-
*/
|
|
452
|
-
function get_hydrated_text(anchor, end) {
|
|
453
|
-
var first = get_next_sibling(anchor);
|
|
454
|
-
|
|
455
|
-
if (first === end) {
|
|
456
|
-
return null;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if (first?.nodeType === TEXT_NODE && get_next_sibling(first) === end) {
|
|
460
|
-
return /** @type {Text} */ (first);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
clear_expression_range(anchor, end);
|
|
464
|
-
return null;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
372
|
/**
|
|
468
373
|
* @param {Node} anchor
|
|
469
374
|
* @param {Node} end
|
|
470
375
|
* @returns {void}
|
|
471
376
|
*/
|
|
472
|
-
function clear_expression_range(anchor, end) {
|
|
377
|
+
export function clear_expression_range(anchor, end) {
|
|
473
378
|
var current = get_next_sibling(anchor);
|
|
474
379
|
|
|
475
380
|
while (current !== null && current !== end) {
|
|
@@ -487,7 +392,7 @@ function clear_expression_range(anchor, end) {
|
|
|
487
392
|
* @returns {void}
|
|
488
393
|
*/
|
|
489
394
|
function settle_hydration(end) {
|
|
490
|
-
if (hydrating) {
|
|
395
|
+
if (HYDRATION && hydrating) {
|
|
491
396
|
set_hydrate_node(end);
|
|
492
397
|
}
|
|
493
398
|
}
|