Skip to content

Commit 62bf167

Browse files
committed
revert strict dom check
1 parent 1bf68d8 commit 62bf167

File tree

9 files changed

+31
-55
lines changed

9 files changed

+31
-55
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.
66
import * as b from '#compiler/builders';
77
import { is_custom_element_node } from '../../../../nodes.js';
88
import { build_template_chunk } from './utils.js';
9-
import { ELEMENT_NODE, TEXT_NODE } from '#client/constants';
109

1110
/**
1211
* Processes an array of template nodes, joining sibling text/expression nodes
@@ -26,19 +25,15 @@ export function process_children(nodes, initial, is_element, context) {
2625
/** @type {Sequence} */
2726
let sequence = [];
2827

29-
/**
30-
* @param {boolean} is_text
31-
* @param {number} node_type
32-
**/
33-
function get_node(is_text, node_type) {
28+
/** @param {boolean} is_text */
29+
function get_node(is_text) {
3430
if (skipped === 0) {
3531
return prev(is_text);
3632
}
3733

3834
return b.call(
3935
'$.sibling',
4036
prev(false),
41-
b.literal(node_type),
4237
(is_text || skipped !== 1) && b.literal(skipped),
4338
is_text && b.true
4439
);
@@ -49,10 +44,7 @@ export function process_children(nodes, initial, is_element, context) {
4944
* @param {string} name
5045
*/
5146
function flush_node(is_text, name) {
52-
const expression = get_node(
53-
is_text,
54-
name === 'text' ? TEXT_NODE : name === 'node' ? 0 : ELEMENT_NODE
55-
);
47+
const expression = get_node(is_text);
5648
let id = expression;
5749

5850
if (id.type !== 'Identifier') {

packages/svelte/src/internal/client/dom/operations.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import { hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
33
import { DEV } from 'esm-env';
44
import { init_array_prototype_warnings } from '../dev/equality.js';
55
import { get_descriptor, is_extensible } from '../../shared/utils.js';
6-
import { COMMENT_NODE, TEXT_NODE, EFFECT_RAN } from '#client/constants';
7-
import { HYDRATION_END, HYDRATION_ERROR } from '../../../constants.js';
8-
import { hydration_mismatch } from '../warnings.js';
96
import { active_effect } from '../runtime.js';
107
import { async_mode_flag } from '../../flags/index.js';
8+
import { TEXT_NODE, EFFECT_RAN } from '#client/constants';
119

1210
// export these for reference in the compiled code, making global name deduplication unnecessary
1311
/** @type {Window} */
@@ -162,40 +160,26 @@ export function first_child(fragment, is_text) {
162160
/**
163161
* Don't mark this as side-effect-free, hydration needs to walk all nodes
164162
* @param {TemplateNode} node
165-
* @param {number} node_type
166163
* @param {number} count
167-
* @param {boolean} add_text
164+
* @param {boolean} is_text
168165
* @returns {Node | null}
169166
*/
170-
export function sibling(node, node_type, count = 1, add_text = false) {
171-
var next_sibling = hydrating ? hydrate_node : node;
167+
export function sibling(node, count = 1, is_text = false) {
168+
let next_sibling = hydrating ? hydrate_node : node;
172169
var last_sibling;
173170

174171
while (count--) {
175172
last_sibling = next_sibling;
176173
next_sibling = /** @type {TemplateNode} */ (get_next_sibling(next_sibling));
177-
if (
178-
(next_sibling === null && !add_text) ||
179-
(next_sibling?.nodeType === COMMENT_NODE &&
180-
/** @type {Comment} */ (next_sibling).data === HYDRATION_END)
181-
) {
182-
hydration_mismatch();
183-
throw HYDRATION_ERROR;
184-
}
185174
}
186175

187176
if (!hydrating) {
188177
return next_sibling;
189178
}
190179

191-
if (hydrating && node_type !== 0 && !add_text && next_sibling?.nodeType !== node_type) {
192-
hydration_mismatch();
193-
throw HYDRATION_ERROR;
194-
}
195-
196180
// if a sibling {expression} is empty during SSR, there might be no
197181
// text node to hydrate — we must therefore create one
198-
if (add_text && next_sibling?.nodeType !== TEXT_NODE) {
182+
if (is_text && next_sibling?.nodeType !== TEXT_NODE) {
199183
var text = create_text();
200184
// If the next sibling is `null` and we're handling text then it's because
201185
// the SSR content was empty for the text, so we need to generate a new text
@@ -210,7 +194,7 @@ export function sibling(node, node_type, count = 1, add_text = false) {
210194
}
211195

212196
set_hydrate_node(next_sibling);
213-
return next_sibling;
197+
return /** @type {TemplateNode} */ (next_sibling);
214198
}
215199

216200
/**

packages/svelte/tests/snapshot/samples/await-block-scope/_expected/client/index.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export default function Await_block_scope($$anchor) {
1919

2020
$.reset(button);
2121

22-
var node = $.sibling(button, 0, 2);
22+
var node = $.sibling(button, 2);
2323

2424
$.await(node, () => $.get(promise), null, ($$anchor, counter) => {});
2525

26-
var text_1 = $.sibling(node, 3);
26+
var text_1 = $.sibling(node);
2727

2828
$.template_effect(() => {
2929
$.set_text(text, `clicks: ${counter.count ?? ''}`);

packages/svelte/tests/snapshot/samples/bind-component-snippet/_expected/client/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function Bind_component_snippet($$anchor) {
2828
}
2929
});
3030

31-
var text_1 = $.sibling(node, 3);
31+
var text_1 = $.sibling(node);
3232

3333
$.template_effect(() => $.set_text(text_1, ` value: ${$.get(value) ?? ''}`));
3434
$.append($$anchor, fragment);

packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/client/main.svelte.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ export default function Main($$anchor) {
1313

1414
$.set_attribute(div, 'foobar', x);
1515

16-
var svg = $.sibling(div, 1, 2);
16+
var svg = $.sibling(div, 2);
1717

1818
$.set_attribute(svg, 'viewBox', x);
1919

20-
var custom_element = $.sibling(svg, 1, 2);
20+
var custom_element = $.sibling(svg, 2);
2121

2222
$.set_custom_element_data(custom_element, 'fooBar', x);
2323

24-
var div_1 = $.sibling(custom_element, 1, 2);
25-
var svg_1 = $.sibling(div_1, 1, 2);
26-
var custom_element_1 = $.sibling(svg_1, 1, 2);
24+
var div_1 = $.sibling(custom_element, 2);
25+
var svg_1 = $.sibling(div_1, 2);
26+
var custom_element_1 = $.sibling(svg_1, 2);
2727

2828
$.template_effect(() => $.set_custom_element_data(custom_element_1, 'fooBar', y()));
2929

packages/svelte/tests/snapshot/samples/nullish-coallescence-omittance/_expected/client/index.svelte.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ export default function Nullish_coallescence_omittance($$anchor) {
1212

1313
h1.textContent = 'Hello, world!';
1414

15-
var b = $.sibling(h1, 1, 2);
15+
var b = $.sibling(h1, 2);
1616

1717
b.textContent = '123';
1818

19-
var button = $.sibling(b, 1, 2);
19+
var button = $.sibling(b, 2);
2020

2121
button.__click = [on_click, count];
2222

2323
var text = $.child(button);
2424

2525
$.reset(button);
2626

27-
var h1_1 = $.sibling(button, 1, 2);
27+
var h1_1 = $.sibling(button, 2);
2828

2929
h1_1.textContent = 'Hello, world';
3030
$.template_effect(() => $.set_text(text, `Count is ${$.get(count) ?? ''}`));

packages/svelte/tests/snapshot/samples/purity/_expected/client/index.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default function Purity($$anchor) {
1010

1111
p.textContent = '0';
1212

13-
var p_1 = $.sibling(p, 1, 2);
13+
var p_1 = $.sibling(p, 2);
1414

1515
p_1.textContent = location.href;
1616

17-
var node = $.sibling(p_1, 0, 2);
17+
var node = $.sibling(p_1, 2);
1818

1919
Child(node, { prop: encodeURIComponent('hello') });
2020
$.append($$anchor, fragment);

packages/svelte/tests/snapshot/samples/skip-static-subtree/_expected/client/index.svelte.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,43 @@ var root = $.from_html(`<header><nav><a href="/">Home</a> <a href="/away">Away</
55

66
export default function Skip_static_subtree($$anchor, $$props) {
77
var fragment = root();
8-
var main = $.sibling($.first_child(fragment), 1, 2);
8+
var main = $.sibling($.first_child(fragment), 2);
99
var h1 = $.child(main);
1010
var text = $.child(h1, true);
1111

1212
$.reset(h1);
1313

14-
var node = $.sibling(h1, 0, 10);
14+
var node = $.sibling(h1, 10);
1515

1616
$.html(node, () => $$props.content);
1717
$.next(14);
1818
$.reset(main);
1919

20-
var cant_skip = $.sibling(main, 1, 2);
20+
var cant_skip = $.sibling(main, 2);
2121
var custom_elements = $.child(cant_skip);
2222

2323
$.set_custom_element_data(custom_elements, 'with', 'attributes');
2424
$.reset(cant_skip);
2525

26-
var div = $.sibling(cant_skip, 1, 2);
26+
var div = $.sibling(cant_skip, 2);
2727
var input = $.child(div);
2828

2929
$.autofocus(input, true);
3030
$.reset(div);
3131

32-
var div_1 = $.sibling(div, 1, 2);
32+
var div_1 = $.sibling(div, 2);
3333
var source = $.child(div_1);
3434

3535
source.muted = true;
3636
$.reset(div_1);
3737

38-
var select = $.sibling(div_1, 1, 2);
38+
var select = $.sibling(div_1, 2);
3939
var option = $.child(select);
4040

4141
option.value = option.__value = 'a';
4242
$.reset(select);
4343

44-
var img = $.sibling(select, 1, 2);
44+
var img = $.sibling(select, 2);
4545

4646
$.next(2);
4747
$.template_effect(() => $.set_text(text, $$props.title));

packages/svelte/tests/snapshot/samples/state-proxy-literal/_expected/client/index.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export default function State_proxy_literal($$anchor) {
1818

1919
$.remove_input_defaults(input);
2020

21-
var input_1 = $.sibling(input, 1, 2);
21+
var input_1 = $.sibling(input, 2);
2222

2323
$.remove_input_defaults(input_1);
2424

25-
var button = $.sibling(input_1, 1, 2);
25+
var button = $.sibling(input_1, 2);
2626

2727
button.__click = [reset, str, tpl];
2828
$.bind_value(input, () => $.get(str), ($$value) => $.set(str, $$value));

0 commit comments

Comments
 (0)