Skip to content

Commit b514499

Browse files
authored
Merge branch 'main' into perf/router-view-rerenders
2 parents db036a5 + e978eb8 commit b514499

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

packages/router/rollup.config.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const packageConfigs = packageBuilds.map(buildName =>
5959
packageBuilds.forEach(buildName => {
6060
if (buildName === 'cjs') {
6161
packageConfigs.push(createProductionConfig(buildName))
62-
} else if (buildName === 'global') {
62+
} else if (buildName === 'global' || buildName === 'browser') {
6363
packageConfigs.push(createMinifiedConfig(buildName))
6464
}
6565
})
@@ -125,6 +125,10 @@ function createConfig(buildName, output, plugins = []) {
125125
// Global and Browser ESM builds inlines everything so that they can be
126126
// used alone.
127127
external,
128+
treeshake: {
129+
// Ensure @vue/devtools-api can be treeshaken in production builds
130+
moduleSideEffects: false,
131+
},
128132
plugins: [
129133
tsPlugin,
130134
createReplacePlugin(
@@ -224,7 +228,7 @@ function createMinifiedConfig(format) {
224228
return createConfig(
225229
format,
226230
{
227-
file: `dist/${name}.${format}.prod.js`,
231+
file: outputConfigs[format].file.replace(/.js$/, '.prod.js'),
228232
format: outputConfigs[format].format,
229233
},
230234
[

packages/router/src/RouterLink.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export interface RouterLinkProps extends RouterLinkOptions {
8383
| 'time'
8484
| 'true'
8585
| 'false'
86+
87+
/**
88+
* Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
89+
*/
90+
viewTransition?: boolean
8691
}
8792

8893
/**
@@ -106,7 +111,13 @@ export interface UseLinkOptions<Name extends keyof RouteMap = keyof RouteMap> {
106111
| RouteLocationAsPath
107112
| RouteLocationRaw
108113
>
114+
109115
replace?: MaybeRef<boolean | undefined>
116+
117+
/**
118+
* Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
119+
*/
120+
viewTransition?: boolean
110121
}
111122

112123
/**
@@ -214,10 +225,19 @@ export function useLink<Name extends keyof RouteMap = keyof RouteMap>(
214225
e: MouseEvent = {} as MouseEvent
215226
): Promise<void | NavigationFailure> {
216227
if (guardEvent(e)) {
217-
return router[unref(props.replace) ? 'replace' : 'push'](
228+
const p = router[unref(props.replace) ? 'replace' : 'push'](
218229
unref(props.to)
219230
// avoid uncaught errors are they are logged anyway
220231
).catch(noop)
232+
if (
233+
props.viewTransition &&
234+
typeof document !== 'undefined' &&
235+
'startViewTransition' in document
236+
) {
237+
// @ts-expect-error: not added to types yet
238+
document.startViewTransition(() => p)
239+
}
240+
return p
221241
}
222242
return Promise.resolve()
223243
}

packages/router/src/router.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ export function createRouter(options: RouterOptions): Router {
10221022
const shouldRedirect = handleRedirectRecord(toLocation)
10231023
if (shouldRedirect) {
10241024
pushWithRedirect(
1025-
assign(shouldRedirect, { replace: true }),
1025+
assign(shouldRedirect, { replace: true, force: true }),
10261026
toLocation
10271027
).catch(noop)
10281028
return
@@ -1063,7 +1063,9 @@ export function createRouter(options: RouterOptions): Router {
10631063
// the error is already handled by router.push we just want to avoid
10641064
// logging the error
10651065
pushWithRedirect(
1066-
(error as NavigationRedirectError).to,
1066+
assign(locationAsObject((error as NavigationRedirectError).to), {
1067+
force: true,
1068+
}),
10671069
toLocation
10681070
// avoid an uncaught rejection, let push call triggerError
10691071
)

0 commit comments

Comments
 (0)