Fix that timer.addAction reverses order when splicing multiple events at same timestamp (#611)

* Add test for event ordering utilizing final html testing method added by Justin (with thanks)

* Found an error where two mutation events had the same timestamp, but one removed a node added in the other. The `actions.splice` method was reversing their order and triggering a 'Node with id [...] not found' error
This commit is contained in:
Eoghan Murray
2026-04-01 12:00:00 +08:00
committed by GitHub
parent cd782c5f97
commit 2b2b44e54e
4 changed files with 218 additions and 1 deletions

View File

@@ -0,0 +1,123 @@
import { EventType, eventWithTime, IncrementalSource } from '../../src/types';
const now = Date.now();
const events: eventWithTime[] = [
{
type: EventType.DomContentLoaded,
data: {},
timestamp: now,
},
{
type: EventType.Load,
data: {},
timestamp: now + 10,
},
{
type: EventType.Meta,
data: {
href: 'http://localhost',
width: 1000,
height: 800,
},
timestamp: now + 10,
},
// full snapshot:
{
data: {
node: {
id: 1,
type: 0,
childNodes: [
{ id: 2, name: 'html', type: 1, publicId: '', systemId: '' },
{
id: 3,
type: 2,
tagName: 'html',
attributes: { lang: 'en' },
childNodes: [
{
id: 4,
type: 2,
tagName: 'head',
attributes: {},
childNodes: [],
},
{
id: 100,
type: 2,
tagName: 'body',
attributes: {},
childNodes: [
{
id: 101,
type: 2,
tagName: 'span',
attributes: {},
childNodes: [
{
id: 102,
type: 3,
textContent: 'Initial',
},
],
},
],
},
],
},
],
},
initialOffset: { top: 0, left: 0 },
},
type: EventType.FullSnapshot,
timestamp: now + 20,
},
// 1st mutation that modifies text content
{
data: {
adds: [],
texts: [
{
id: 102,
value: 'Intermediate - incorrect',
}
],
source: IncrementalSource.Mutation,
removes: [],
attributes: [],
},
type: EventType.IncrementalSnapshot,
timestamp: now + 30,
},
// 2nd mutation (with same timestamp) that modifies text content
{
data: {
adds: [],
texts: [
{
id: 102,
value: 'Final - correct',
}
],
source: IncrementalSource.Mutation,
removes: [],
attributes: [],
},
type: EventType.IncrementalSnapshot,
timestamp: now + 30,
},
// dummy - presence triggers a bug
{
data: {
adds: [],
texts: [],
source: IncrementalSource.Mutation,
removes: [],
attributes: [],
},
type: EventType.IncrementalSnapshot,
timestamp: now + 35,
},
];
export default events;