Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix insertExpression throw #307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion packages/dom-expressions/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,16 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
if (value === current) return current;
const t = typeof value,
multi = marker !== undefined;
parent = (multi && current[0] && current[0].parentNode) || parent;
const maybeChangedParent = (multi && current[0] && current[0].parentNode);

// Don't change the parent if that would lead us to run into "Uncaught DOMException: Failed to execute 'replaceChild' on 'Node': The new child element contains the parent."
if(maybeChangedParent && maybeChangedParent !== value){
// Previously, if maybeChangedParent was truthy, it was always used (the parent was always assumed to be the same as the parent of the first child).
// According to fabiospampinato on discord (https://discord.com/channels/722131463138705510/751355413701591120/1195741968538554438) this is to check if a node should actually be removed from its parent (since it could have moved)
// Probably the whole approach here should be re-thought, but the previous assumption above resulted in bug 1 detailed in https://github.com/solidjs/solid/issues/2030
// This if statement is the least possible change to make that case work, probably without breaking anything else
parent = maybeChangedParent;
}

if (t === "string" || t === "number") {
if (sharedConfig.context) return current;
Expand Down
Loading