WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/svelte/src/internal/client/dom/blocks/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ function reconcile(state, array, anchor, flags, get_key) {
stashed = [];

while (current !== null && current !== effect) {
// Detect cycle in linked list to prevent infinite loop
if (seen !== undefined && seen.has(current)) {
if (DEV) {
console.warn('Svelte: cycle detected in each block linked list, breaking to prevent infinite loop');
}
break;
}
(seen ??= new Set()).add(current);
stashed.push(current);
current = current.next;
Expand Down Expand Up @@ -536,7 +543,21 @@ function reconcile(state, array, anchor, flags, get_key) {
}
}

// Track visited nodes to detect cycles in the linked list
// A cycle would cause an infinite loop and eventually a RangeError
/** @type {Set<Effect>} */
var visited = new Set();

while (current !== null) {
// Detect cycle in linked list to prevent infinite loop
if (visited.has(current)) {
if (DEV) {
console.warn('Svelte: cycle detected in each block linked list, breaking to prevent infinite loop');
}
break;
}
visited.add(current);

// If the each block isn't inert, then inert effects are currently outroing and will be removed once the transition is finished
if ((current.f & INERT) === 0 && current !== state.fallback) {
to_destroy.push(current);
Expand Down