Skip to content

🐛 [RUM-19914] Stop retaining Vue views and errors queued before RUM starts - #5280

Merged
BeltranBulbarellaDD merged 3 commits into
mainfrom
beltran.bulbarella/vue-plugin-stop-ssr-memory-leak-from-pre-384e1c3d
Nov 17, 2026
Merged

BeltranBulbarellaDD merged 3 commits into
mainfrom
beltran.bulbarella/vue-plugin-stop-ssr-memory-leak-from-pre-384e1c3d

Conversation

@BeltranBulbarellaDD

@BeltranBulbarellaDD BeltranBulbarellaDD commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The Vue plugin queued callbacks in unbounded module-level arrays until RUM initialized or started. During server-side rendering RUM never starts, so every navigation (closure over to.matched, route records holding components) and every reported error (closure over the component instance) was retained forever. This is the Vue counterpart of the Angular fix in #5237 (issue #5193).

Jira: RUM-19914

Changes

  • vuePlugin buffers plain data in a BufferedObservable capped at 500 (like the core pre-start buffer): view names and fully built error payloads. Buffered items are replayed in order on onInit / onRumStart; repeated onInit keeps a single view subscriber.
  • The router wrapper computes the view name at navigation time, so route records are not kept.
  • addVueError builds the whole payload (handling stack, clocks, component stack, dd_context) eagerly inside callMonitored, so the component instance is not kept.
  • Internal onRumInit / onRumStart helpers are removed (not exported). Public API, view names, error payloads and the router: true warning are unchanged. Replay now happens one microtask after init, as in the Angular plugin.

Test instructions

  • yarn test:unit packages/browser-rum-vue: new specs cover replay order, delivery after init, single delivery on repeated init, the router warning, the 500 cap for views and errors, and a throwing dd_context getter (43/43 pass locally). yarn typecheck, eslint and prettier pass locally.
  • Manual (local): in test/apps/vue-router-app, delay datadogRum.init 500 ms after mount, a navigation to /user/42 and an addVueError call, collect events with beforeSend. After init, the / view, the pre-init error error and the /user/:id view are received.
  • Retention was checked locally with a temporary WeakRef + gc() spec (Chromium with --expose-gc, no app mounted): route record and component instance were retained before the fix and collected after. That spec is not included.

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

refs: RUM-19914

Buffer view names and prebuilt error payloads in a capped BufferedObservable instead of callbacks that retain route records and component instances (same approach as the Angular plugin, #5237).
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce 192.54 KiB 192.54 KiB 0 B 0.00% ✅
Rum 192.52 KiB 192.52 KiB 0 B 0.00% ✅
Rum Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Salesforce Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Salesforce Recorder 32.62 KiB 32.62 KiB 0 B 0.00% ✅
Rum Recorder 32.62 KiB 32.62 KiB 0 B 0.00% ✅
Logs 60.26 KiB 60.26 KiB 0 B 0.00% ✅
Rum Slim 148.45 KiB 148.45 KiB 0 B 0.00% ✅
Worker 24.23 KiB 24.23 KiB 0 B 0.00% ✅
Rum Shopify 223.58 KiB 223.58 KiB 0 B 0.00% ✅
Rum Shopify Profiler 8.17 KiB 8.17 KiB 0 B 0.00% ✅
Rum Shopify Recorder 4.85 KiB 4.85 KiB 0 B 0.00% ✅

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 95.24%
• Overall Coverage: 78.08% (-0.03%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 1468ce7 | Docs | View more details | Give us feedback!

@BeltranBulbarellaDD
BeltranBulbarellaDD marked this pull request as ready for review November 13, 2026 14:25
@BeltranBulbarellaDD
BeltranBulbarellaDD requested a review from a team as a code owner November 13, 2026 14:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T14:28:04.272983Z 7ec4935 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-13T14:28:35.045714Z 7ec4935 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ec49350e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

The most critical issue is a race condition in vuePlugin.ts where retrying initialization before microtasks drain causes buffered view names to be dropped, potentially leaving RUM unstarted when router: true is set. Separately, addVueError.ts captures the handling stack inside callMonitored rather than before it, producing incorrect stack frames for Vue error diagnostics.

Open Bits AI session

🤖 Bits Code Review · Commit 7ec4935

expect(startView).toHaveBeenCalledOnceWith('/a')
})

it('starts each view once when onInit is called several times', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion

if we remove viewSubscription?.unsubscribe() line from vuePlugin this test will still pass

let's assign first initPlugin call to a variable as well and check that
expect(firstStartView).not.toHaveBeenCalled()

…onInit

refs: RUM-19914

Keep the first onInit's startView spy and check it is never called, so the test fails if the previous subscription is not unsubscribed.
@BeltranBulbarellaDD
BeltranBulbarellaDD merged commit 74cfff0 into main Nov 17, 2026
31 checks passed
@BeltranBulbarellaDD
BeltranBulbarellaDD deleted the beltran.bulbarella/vue-plugin-stop-ssr-memory-leak-from-pre-384e1c3d branch November 17, 2026 12:34
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 17, 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