mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-24 09:23:04 -04:00
Handle nested document.write where parent gets deleted
Handles a real life case where a nested document.write mutates the DOM in a way where there outer document.write loses its parent.
This commit is contained in:
@@ -690,9 +690,16 @@ pub fn write(self: *Document, text: []const []const u8, page: *Page) !void {
|
||||
}
|
||||
|
||||
// Determine insertion point:
|
||||
// - If _write_insertion_point is set, continue from there (subsequent write)
|
||||
// - Otherwise, start after the script (first write)
|
||||
var insert_after: ?*Node = self._write_insertion_point orelse script.asNode();
|
||||
// - If _write_insertion_point is set and still parented correctly, continue from there
|
||||
// - Otherwise, start after the script (first write, or previous insertion point was removed)
|
||||
var insert_after: ?*Node = blk: {
|
||||
if (self._write_insertion_point) |wip| {
|
||||
if (wip._parent == parent) {
|
||||
break :blk wip;
|
||||
}
|
||||
}
|
||||
break :blk script.asNode();
|
||||
};
|
||||
|
||||
for (children_to_insert.items) |child| {
|
||||
// Clear parent pointer (child is currently parented to fragment/HTML wrapper)
|
||||
|
||||
Reference in New Issue
Block a user