reuse serialized nodes ids (#12)

* reuse serialized nodes ids

With this patch, each DOM node keeps its id during its existence. This
allows to apply RRWeb events to previous snapshots if needed.

`resetId` has been removed because it loses its meaning: calling it
would not reset the existing nodes ids anymore, only the new ones.

Since we don't reset the id anymore, we may exhaust the available ids
quicker, but Number.MAX_SAFE_INTEGER (2 ** 53 - 1) is pretty large, so I
doubt this'll cause any problem.

* improv TS typing

The `nAsINode` variable was not very elegant.  Simplify this by removing
the cast, and make the INode interface compatible with Node.

* update typings
This commit is contained in:
Benoît Zugmeyer
2026-04-01 12:00:00 +08:00
committed by yz-yu
parent 2c5bb90b2f
commit ad816f7b7f
4 changed files with 16 additions and 17 deletions

4
typings/index.d.ts vendored
View File

@@ -1,4 +1,4 @@
import snapshot, { serializeNodeWithId, resetId } from './snapshot';
import snapshot, { serializeNodeWithId } from './snapshot';
import rebuild, { buildNodeWithSN } from './rebuild';
export * from './types';
export { snapshot, serializeNodeWithId, resetId, rebuild, buildNodeWithSN };
export { snapshot, serializeNodeWithId, rebuild, buildNodeWithSN };