Skip to content

Conversation

@karlseguin
Copy link
Collaborator

No description provided.

pub fn _remove(self: *parser.Element) !void {
const as_node: *parser.Node = @ptrCast(self);
const parent = try parser.nodeParentNode(as_node) orelse return;
_ = try Node._removeChild(parent, as_node);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I doubt this will update all location where a pointer to the deleted element was stored.
For example:

Image

Code:

document.body.innerHTML = `
  <div class="preference">
    <label for="cheese">Do you like cheese?</label>
    <input type="checkbox" name="cheese" id="cheese" />
  </div>
`;

const label = document.querySelector('label[for="cheese"]');
label.control

const input = document.getElementById('cheese');
if (input) {
  input.remove();
}

label.control

Maybe just leave a TODO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively elements could have a tombstone flag

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a widespread issue for any part of the code that removes/moves nodes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, I personally prefer leaving breadcrumbs around to help our future debugging selves.

@karlseguin karlseguin merged commit 3c64ed1 into main Jul 17, 2025
10 checks passed
@karlseguin karlseguin deleted the element_remove branch July 17, 2025 13:44
@github-actions github-actions bot locked and limited conversation to collaborators Jul 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants