Repository navigation
fix: capture the router's current route when pages call capture during navigation - #221
Merged
Merged
Conversation
Member
Author
|
Review notes:
Two problems turned up while tracing this. Both already exist on
|
…oute # Conflicts: # test/runtime-plugin.test.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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
capture()defaulted tonuxtApp._route. With the pages router, Nuxt syncs_routeonly after the new page's Suspense resolves, so a page that calleduseNuxtUTM().capture()fromsetuporonMountedafter a client-side navigation recorded the previous route instead of its own. Navigating from/to/landing?utm_source=newsletterand capturing on mount stored/again, and since that matched the existing entry for the session, deduplication dropped it and the newsletter campaign was never recorded.capture()now defaults to the router's current route, which vue-router updates before the new page renders. It reads it withunref(router.currentRoute)because apps without the pages router use Nuxt's minimal router, whosecurrentRouteis a computed over the route it assigns to_routefrom Nuxt 3.9.1 onward but the reactive route object itself in 3.0.0 through 3.9.0. Reading.valuethere would throw on mount, and the module supports Nuxt from 3.0.0. Route-change tracking already passed the destination route explicitly, so it behaves as before.The new
test/fixtures/pagesfixture has a home page linking to/landing?utm_source=newsletterand a landing page that callscapture()on mount. Its browser test fails without the fix (expected undefined to be 'newsletter') and passes with it. The runtime plugin unit tests now set the mocked router's current route as a ref instead of_route, and a new case passes a plain route object the way the minimal router before Nuxt 3.9.1 does. That case failed with.value(Cannot read properties of undefined (reading 'query')) and passes withunref. The new files pass both the current ESLint config and the Prettier-only config from #220.Validation:
pnpm format:checkon the changed files,pnpm lint --max-warnings 0,pnpm test:types,pnpm dev:build,pnpm test(83 tests),pnpm test:package, andpnpm test:compatibilityagainst Nuxt 4 and Nuxt 3 pass.