Skip to content

Commit b61339a

Browse files
authored
Revert "chore: consistent nextSibling usage (#11694)"
This reverts commit f3dbfc9.
1 parent f3dbfc9 commit b61339a

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

packages/svelte/src/internal/client/dom/blocks/each.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
HYDRATION_START
1010
} from '../../../../constants.js';
1111
import { hydrate_anchor, hydrate_nodes, hydrating, set_hydrating } from '../hydration.js';
12-
import { clear_text_content, empty, next_sibling } from '../operations.js';
12+
import { clear_text_content, empty } from '../operations.js';
1313
import { remove } from '../reconciler.js';
1414
import { untrack } from '../../runtime.js';
1515
import {
@@ -175,15 +175,15 @@ export function each(anchor, flags, get_collection, get_key, render_fn, fallback
175175
var key = get_key(value, i);
176176
item = create_item(child_open, child_anchor, prev, null, value, key, i, render_fn, flags);
177177
state.items.set(key, item);
178-
child_anchor = /** @type {Comment} */ (next_sibling(child_anchor));
178+
child_anchor = /** @type {Comment} */ (child_anchor.nextSibling);
179179

180180
prev = item;
181181
}
182182

183183
// remove excess nodes
184184
if (length > 0) {
185185
while (child_anchor !== anchor) {
186-
var next = /** @type {import('#client').TemplateNode} */ (next_sibling(child_anchor));
186+
var next = /** @type {import('#client').TemplateNode} */ (child_anchor.nextSibling);
187187
/** @type {import('#client').TemplateNode} */ (child_anchor).remove();
188188
child_anchor = next;
189189
}
@@ -501,7 +501,7 @@ function move(item, next, anchor) {
501501
var node = /** @type {import('#client').TemplateNode} */ (item.o);
502502

503503
while (node !== end) {
504-
var next_node = /** @type {import('#client').TemplateNode} */ (next_sibling(node));
504+
var next_node = /** @type {import('#client').TemplateNode} */ (node.nextSibling);
505505
dest.before(node);
506506
node = next_node;
507507
}

packages/svelte/src/internal/client/dom/blocks/svelte-head.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { hydrate_anchor, hydrate_nodes, hydrating, set_hydrate_nodes } from '../hydration.js';
2-
import { empty, next_sibling } from '../operations.js';
2+
import { empty } from '../operations.js';
33
import { block } from '../../reactivity/effects.js';
4-
import { HYDRATION_START } from '../../../../constants.js';
4+
import { HYDRATION_END, HYDRATION_START } from '../../../../constants.js';
55

66
/**
77
* @type {Node | undefined}
@@ -37,11 +37,11 @@ export function head(render_fn) {
3737
head_anchor.nodeType !== 8 ||
3838
/** @type {Comment} */ (head_anchor).data !== HYDRATION_START
3939
) {
40-
head_anchor = /** @type {import('#client').TemplateNode} */ (next_sibling(head_anchor));
40+
head_anchor = /** @type {import('#client').TemplateNode} */ (head_anchor.nextSibling);
4141
}
4242

4343
head_anchor = /** @type {import('#client').TemplateNode} */ (hydrate_anchor(head_anchor));
44-
head_anchor = /** @type {import('#client').TemplateNode} */ (next_sibling(head_anchor));
44+
head_anchor = /** @type {import('#client').TemplateNode} */ (head_anchor.nextSibling);
4545
} else {
4646
anchor = document.head.appendChild(empty());
4747
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { DEV } from 'esm-env';
22
import { HYDRATION_END, HYDRATION_START, HYDRATION_ERROR } from '../../../constants.js';
33
import * as w from '../warnings.js';
4-
import { next_sibling } from './operations.js';
54

65
/**
76
* Use this variable to guard everything related to hydration code so it can be treeshaken out
@@ -50,7 +49,7 @@ export function hydrate_anchor(node) {
5049
var nodes = [];
5150
var depth = 0;
5251

53-
while ((current = next_sibling(/** @type {Node} */ (current))) !== null) {
52+
while ((current = /** @type {Node} */ (current).nextSibling) !== null) {
5453
if (current.nodeType === 8) {
5554
var data = /** @type {Comment} */ (current).data;
5655

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,6 @@ export function first_child(fragment, is_text) {
173173
return hydrate_anchor(first_node);
174174
}
175175

176-
/**
177-
* @template {Node} N
178-
* @param {N} node
179-
* @returns {Node | null}
180-
*/
181-
/*#__NO_SIDE_EFFECTS__*/
182-
export function next_sibling(node) {
183-
return next_sibling_get.call(node);
184-
}
185-
186176
/**
187177
* @template {Node} N
188178
* @param {N} node

packages/svelte/src/internal/client/render.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
clear_text_content,
55
create_element,
66
empty,
7-
init_operations,
8-
next_sibling
7+
init_operations
98
} from './dom/operations.js';
109
import { HYDRATION_ERROR, HYDRATION_START, PassiveDelegatedEvents } from '../../constants.js';
1110
import { flush_sync, push, pop, current_component_context } from './runtime.js';
@@ -107,7 +106,6 @@ export function mount(component, options) {
107106
if (DEV) {
108107
validate_component(component);
109108
}
110-
init_operations();
111109

112110
const anchor = options.anchor ?? options.target.appendChild(empty());
113111
// Don't flush previous effects to ensure order of outer effects stays consistent
@@ -135,7 +133,6 @@ export function hydrate(component, options) {
135133
if (DEV) {
136134
validate_component(component);
137135
}
138-
init_operations();
139136

140137
const target = options.target;
141138
const previous_hydrate_nodes = hydrate_nodes;
@@ -147,13 +144,12 @@ export function hydrate(component, options) {
147144
return flush_sync(() => {
148145
set_hydrating(true);
149146

150-
/** @type {Node | null} */
151147
var node = target.firstChild;
152148
while (
153149
node &&
154150
(node.nodeType !== 8 || /** @type {Comment} */ (node).data !== HYDRATION_START)
155151
) {
156-
node = next_sibling(node);
152+
node = node.nextSibling;
157153
}
158154

159155
if (!node) {
@@ -176,6 +172,8 @@ export function hydrate(component, options) {
176172
e.hydration_failed();
177173
}
178174

175+
// If an error occured above, the operations might not yet have been initialised.
176+
init_operations();
179177
clear_text_content(target);
180178

181179
set_hydrating(false);
@@ -204,6 +202,8 @@ export function hydrate(component, options) {
204202
* @returns {Exports}
205203
*/
206204
function _mount(Component, { target, anchor, props = {}, events, context, intro = false }) {
205+
init_operations();
206+
207207
const registered_events = new Set();
208208

209209
const bound_event_listener = handle_event_propagation.bind(null, target);

0 commit comments

Comments
 (0)