Skip to content

fix(vue): release a page's DOM after navigating away from it - #31871

Open
ShaneK wants to merge 2 commits into
mainfrom
FW-6445
Open

ShaneK wants to merge 2 commits into
mainfrom
FW-6445

Conversation

@ShaneK

@ShaneK ShaneK commented Dec 4, 2026

Copy link
Copy Markdown
Member

Issue number: resolves internal


What is the current behavior?

Currently, when a page in an IonRouterOutlet unmounts, Vue Router's route record still points at it, so its DOM is kept around as detached nodes.

What is the new behavior?

  • The outlet clears the route record when a page unmounts, like Vue Router's RouterView does.
  • Pages of a parameterized route (e.g., /message/:id) share a record, so the outlet points it at the visible page. This keeps in-component guards like beforeRouteLeave running on the right page after router.back() and router.go().
  • Added Vitest specs for both.

Does this introduce a breaking change?

  • Yes
  • No

Other information

On a production build of the Vue list starter, opening a message and going back left about 70 detached nodes on 9.0.15. With this change there are none after 1, 3 or 6 round trips, using either the back button or browser back.

@ShaneK
ShaneK requested a review from a team as a code owner December 4, 2026 21:37
@ShaneK
ShaneK requested a review from thetaPC December 4, 2026 21:37
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-framework Ready Ready Preview Dec 4, 2026 9:37pm UTC

Request Review

@thetaPC thetaPC left a comment

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.

LGTM, with minor suggestion

Comment on lines +9 to +12
/**
* Exposes `gc()` so the tests can check that a page is
* released once it leaves the DOM.
*/

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.

  • Turning on --expose-gc at runtime doesn't add gc to the current global, only to contexts created afterward, so the comment doesn't explain why gc comes from runInNewContext
  • Without that, runInNewContext('gc') looks like a roundabout globalThis.gc, and simplifying it breaks every GC assertion in the file
Suggested change
/**
* Exposes `gc()` so the tests can check that a page is
* released once it leaves the DOM.
*/
/**
* Exposes `gc()` so the tests can check that a page is
* released once it leaves the DOM. Setting the flag at
* runtime only adds `gc` to contexts created afterward,
* so read it from a new one.
*/

This branch was successfully deployed

1 active deployment
Preview — 813a3df4 Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants