Skip to content

Conversation

@BenoitZugmeyer
Copy link
Member

Motivation

viewportObservable.spec.ts changes the page to add scrollbars, causing some asynchronous events to be fired after the test has completed. If recorder.spec.ts is executed just after, its test might fail because it'll record those asynchronous events.

This is the same issue we had with scroll.spec.ts. In the past, we tried to be smart and predict which events will be triggered, and wait for them. But it's a bit complex and not reliable on every browsers.

Changes

This commit simplifies this workaround by waiting for two frames. When scrolling/changing viewport, the browser will first paint it, and then emit events. The second frame should reliably come after events are emitted (tested in Chrome, Firefox and Safari).

Test instructions

Reproduce flaky test:

git checkout 56a15f139dec81f010396e6a32e172b2291efcc4
yarn test:unit --seed 26598

Confirm that it's gone when running the tests with the same seed after applying this PR changes

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

`viewportObservable.spec.ts` changes the page to add scrollbars, causing
some asynchronous events to be fired *after* the test has completed.
If `recorder.spec.ts` is executed just after, its test might fail
because it'll record those asynchronous events.

This is the same issue we had with `scroll.spec.ts`. In the past, we
tried to be smart and predict which events will be triggered, and wait
for them. But it's a bit complex and not reliable on every browsers.

This commit simplifies this workaround by waiting for two frames. When
scrolling/changing viewport, the browser will first paint it, and then
emit events. The second frame should reliably come after events are
emitted (tested in Chrome, Firefox and Safari).

Reproduce flaky test:
  git checkout 56a15f1
  yarn test:unit --seed 26598
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/push-uwxqoqksvouq branch from 01da4b6 to 14258e6 Compare February 12, 2026 09:13
@datadog-official
Copy link

datadog-official bot commented Feb 12, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage
Patch Coverage: 100.00%
Overall Coverage: 77.27% (+0.01%)

View detailed report

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 14258e6 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@cit-pr-commenter-54b7da
Copy link

cit-pr-commenter-54b7da bot commented Feb 12, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 169.44 KiB 169.44 KiB 0 B 0.00%
Rum Profiler 4.31 KiB 4.31 KiB 0 B 0.00%
Rum Recorder 24.54 KiB 24.54 KiB 0 B 0.00%
Logs 56.72 KiB 56.72 KiB 0 B 0.00%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 126.26 KiB 126.26 KiB 0 B 0.00%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.004 0.0039 -2.50%
RUM - add action 0.0124 0.0133 +7.26%
RUM - add error 0.0121 0.0123 +1.65%
RUM - add timing 0.0025 0.0025 0.00%
RUM - start view 0.0118 0.0121 +2.54%
RUM - start/stop session replay recording 0.0007 0.0006 -14.29%
Logs - log message 0.0149 0.014 -6.04%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 27.32 KiB 27.75 KiB +441 B
RUM - add action 50.83 KiB 56.63 KiB +5.80 KiB
RUM - add timing 26.93 KiB 26.77 KiB -163 B
RUM - add error 57.36 KiB 55.62 KiB -1.74 KiB
RUM - start/stop session replay recording 26.81 KiB 25.90 KiB -930 B
RUM - start view 452.06 KiB 453.48 KiB +1.42 KiB
Logs - log message 45.88 KiB 45.35 KiB -538 B

🔗 RealWorld

@BenoitZugmeyer BenoitZugmeyer marked this pull request as ready for review February 12, 2026 09:18
@BenoitZugmeyer BenoitZugmeyer requested a review from a team as a code owner February 12, 2026 09:18
@@ -1,9 +1,13 @@
const cleanupTasks: Array<() => void> = []
type CleanupTask = () => unknown
Copy link
Collaborator

Choose a reason for hiding this comment

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

🥜 nitpick:

Suggested change
type CleanupTask = () => unknown
type CleanupTask = () => void | Promise<void>

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my initial thought, but then it lead to a typechecking issue https://gitlab.ddbuild.io/DataDog/browser-sdk/-/jobs/1420187767

Sooo... I just used unknown because we don't really care of the result?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, it's fine

@BenoitZugmeyer BenoitZugmeyer merged commit aad6657 into main Feb 12, 2026
21 checks passed
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/push-uwxqoqksvouq branch February 12, 2026 11:20
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2026
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