Repository navigation
🐛 [RUM-19914] Stop retaining Vue views and errors queued before RUM starts #5280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BeltranBulbarellaDD
merged 3 commits into
main
from
beltran.bulbarella/vue-plugin-stop-ssr-memory-leak-from-pre-384e1c3d
Nov 17, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
7ec4935
fix: stop retaining Vue views and errors queued before RUM starts
BeltranBulbarellaDD 18ebf5c
fix: create Vue error handling stack outside callMonitored
BeltranBulbarellaDD 1468ce7
fix: assert replaced Vue view subscriber is unsubscribed on repeated …
BeltranBulbarellaDD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 1 addition & 29 deletions
30
packages/browser-rum-vue/src/domain/router/startVueRouterView.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
packages/browser-rum-vue/src/domain/router/startVueRouterView.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,24 @@ | ||
| import { version as vueVersion } from 'vue' | ||
| import { toMajorVersionIntegration } from '@datadog/browser-core' | ||
| import { display, toMajorVersionIntegration } from '@datadog/browser-core' | ||
| import type { RumInitConfiguration, RumPluginOnInitOptions, RumPublicApi } from '@datadog/browser-rum-core' | ||
| import { registerCleanupTask } from '../../../browser-core/test' | ||
| import { onRumInit, vuePlugin, resetVuePlugin } from './vuePlugin' | ||
| import { registerCleanupTask, waitNextMicrotask } from '../../../browser-core/test' | ||
| import type { VuePluginConfiguration, VueErrorPayload } from './vuePlugin' | ||
| import { vuePlugin, resetVuePlugin, startVueViewWhenReady, addVueErrorWhenReady } from './vuePlugin' | ||
|
|
||
| const PUBLIC_API = {} as RumPublicApi | ||
|
|
||
| function initPlugin(configuration: VuePluginConfiguration, startView = jasmine.createSpy()) { | ||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises -- onInit never returns a promise for this plugin | ||
| vuePlugin(configuration).onInit({ | ||
| publicApi: { startView } as unknown as RumPublicApi, | ||
| initConfiguration: {} as RumInitConfiguration, | ||
| } as RumPluginOnInitOptions) | ||
| return startView | ||
| } | ||
|
|
||
| function error(message: string) { | ||
| return { error: new Error(message) } as VueErrorPayload | ||
| } | ||
| const INIT_CONFIGURATION = {} as RumInitConfiguration | ||
|
|
||
| describe('vuePlugin', () => { | ||
|
|
@@ -16,22 +30,70 @@ describe('vuePlugin', () => { | |
| expect(vuePlugin()).toEqual(jasmine.objectContaining({ name: 'vue' })) | ||
| }) | ||
|
|
||
| it('calls callbacks registered with onRumInit during onInit', () => { | ||
| const spy = jasmine.createSpy() | ||
| const config = {} | ||
| onRumInit(spy) | ||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises -- onInit never returns a promise for this plugin | ||
| vuePlugin(config).onInit({ publicApi: PUBLIC_API, initConfiguration: INIT_CONFIGURATION } as RumPluginOnInitOptions) | ||
| expect(spy).toHaveBeenCalledOnceWith(config, PUBLIC_API) | ||
| it('replays views notified before onInit, in order', async () => { | ||
| startVueViewWhenReady('/a') | ||
| startVueViewWhenReady('/b') | ||
| const startView = initPlugin({ router: true }) | ||
| await waitNextMicrotask() | ||
| expect(startView.calls.allArgs()).toEqual([['/a'], ['/b']]) | ||
| }) | ||
|
|
||
| it('calls callbacks immediately if onInit was already invoked', () => { | ||
| const spy = jasmine.createSpy() | ||
| const config = {} | ||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises -- onInit never returns a promise for this plugin | ||
| vuePlugin(config).onInit({ publicApi: PUBLIC_API, initConfiguration: INIT_CONFIGURATION } as RumPluginOnInitOptions) | ||
| onRumInit(spy) | ||
| expect(spy).toHaveBeenCalledOnceWith(config, PUBLIC_API) | ||
| it('starts views notified after onInit', async () => { | ||
| const startView = initPlugin({ router: true }) | ||
| await waitNextMicrotask() | ||
| startVueViewWhenReady('/a') | ||
| expect(startView).toHaveBeenCalledOnceWith('/a') | ||
| }) | ||
|
|
||
| it('starts each view once when onInit is called several times', async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if we remove let's assign first |
||
| const firstStartView = initPlugin({ router: true }) | ||
| const startView = initPlugin({ router: true }) | ||
| await waitNextMicrotask() | ||
| startVueViewWhenReady('/a') | ||
| expect(firstStartView).not.toHaveBeenCalled() | ||
| expect(startView).toHaveBeenCalledOnceWith('/a') | ||
| }) | ||
|
|
||
| it('warns and does not start views when router is not enabled', async () => { | ||
| const warnSpy = spyOn(display, 'warn') | ||
| startVueViewWhenReady('/a') | ||
| const startView = initPlugin({}) | ||
| await waitNextMicrotask() | ||
| expect(startView).not.toHaveBeenCalled() | ||
| expect(warnSpy).toHaveBeenCalledOnceWith( | ||
| '`router: true` is missing from the vue plugin configuration, the view will not be tracked.' | ||
| ) | ||
| }) | ||
|
|
||
| it('keeps only the 500 most recent views before onInit', async () => { | ||
| for (let i = 0; i < 501; i++) { | ||
| startVueViewWhenReady(`/${i}`) | ||
| } | ||
| const startView = initPlugin({ router: true }) | ||
| await waitNextMicrotask() | ||
| expect(startView).toHaveBeenCalledTimes(500) | ||
| expect(startView.calls.first().args[0]).toBe('/1') | ||
| }) | ||
|
|
||
| it('replays errors notified before onRumStart, then reports new ones', async () => { | ||
| const addError = jasmine.createSpy() | ||
| const first = error('first') | ||
| addVueErrorWhenReady(first) | ||
| vuePlugin().onRumStart({ addError }) | ||
| await waitNextMicrotask() | ||
| const second = error('second') | ||
| addVueErrorWhenReady(second) | ||
| expect(addError.calls.allArgs()).toEqual([[first], [second]]) | ||
| }) | ||
|
|
||
| it('keeps only the 500 most recent errors before onRumStart', async () => { | ||
| for (let i = 0; i < 501; i++) { | ||
| addVueErrorWhenReady(error(String(i))) | ||
| } | ||
| const addError = jasmine.createSpy() | ||
| vuePlugin().onRumStart({ addError }) | ||
| await waitNextMicrotask() | ||
| expect(addError).toHaveBeenCalledTimes(500) | ||
| }) | ||
|
|
||
| it('sets trackViewsManually when router is true', () => { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.