SIGN IN SIGN UP

fix(replay): replace re-added nodes instead of duplicating them (#4501)

* fix(replay): replace re-added nodes instead of duplicating them

When an add mutation arrives for a node id the mirror already holds and the
node attributes have changed, buildNodeWithSN builds a replacement element and
re-points the mirror id at it. It left the old element in the document with no
mirror id, so no later remove could reach it and it stayed on screen as a
duplicate until the next full snapshot.

Detach the old element before building the replacement. This fixes the
duplicate on both replay paths, with useVirtualDom on and off, because the add
path routes through this function in both modes.

Generated-By: PostHog Desktop
Task-Id: 9d5ecae6-5c86-4c03-a5a2-e90cdbfd10bd

* fix(replay): preserve stylesheet insertion point

* chore: release replay fix with posthog-js only

* fix(replay): preserve stale node when rebuild fails

---------

Co-authored-by: posthog[bot] <206114724+posthog[bot]@users.noreply.github.com>
Co-authored-by: Manoel Aranda Neto <marandaneto@gmail.com>
P
posthog[bot] committed
9e853c11f6a97197667caeeb11849dff776c986c
Parent: 233ac88
Committed by GitHub <noreply@github.com> on 8/24/2026, 9:26:32 AM