Skip to content

Commit 628fe18

Browse files
authored
feat: add helpful diagnostics (#2737)
use nostics
1 parent 4499ca5 commit 628fe18

30 files changed

Lines changed: 685 additions & 295 deletions

packages/router/__tests__/guards/guardToPromiseFn.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { mockWarn } from '../vitest-mock-warn'
55
import { vi, describe, expect, it } from 'vitest'
66

77
const NEXT_DEPRECATION_MESSAGE =
8-
'The `next()` callback in navigation guards is deprecated. Return the value instead of calling `next(value)`.'
8+
'The `next()` callback in navigation guards is deprecated.'
99

1010
// stub those two
1111
const to = START_LOCATION_NORMALIZED

packages/router/__tests__/lazyLoading.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ describe('Lazy Loading', () => {
269269

270270
expect(spy).toHaveBeenCalled()
271271
expect(spy).toHaveBeenLastCalledWith(error)
272-
expect('uncaught error').toHaveBeenWarned()
272+
expect('Uncaught error').toHaveBeenWarned()
273273

274274
expect(router.currentRoute.value).toMatchObject({
275275
path: '/',
@@ -289,7 +289,7 @@ describe('Lazy Loading', () => {
289289
await router.push('/foo').catch(spy)
290290

291291
expect(spy).toHaveBeenCalledTimes(1)
292-
expect('uncaught error').toHaveBeenWarned()
292+
expect('Uncaught error').toHaveBeenWarned()
293293

294294
expect(router.currentRoute.value).toMatchObject({
295295
path: '/',
@@ -318,7 +318,7 @@ describe('Lazy Loading', () => {
318318
await router.push('/foo').catch(spy)
319319

320320
expect(spy).toHaveBeenCalledWith(error)
321-
expect('uncaught error').toHaveBeenWarned()
321+
expect('Uncaught error').toHaveBeenWarned()
322322

323323
expect(router.currentRoute.value).toMatchObject({
324324
path: '/',

packages/router/__tests__/scrollBehavior.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ describe('scrollBehavior', () => {
185185
it('warns if element cannot be found with id but can with selector', () => {
186186
scrollToPosition({ el: '#text .container' })
187187
expect(
188-
`selector "#text .container" should be passed as "el: document.querySelector('#text .container')"`
188+
`el: document.querySelector('#text .container')`
189189
).toHaveBeenWarned()
190190
})
191191

192192
it('warns if element cannot be found with id but can with selector', () => {
193193
scrollToPosition({ el: '#text .container' })
194194
expect(
195-
`selector "#text .container" should be passed as "el: document.querySelector('#text .container')"`
195+
`el: document.querySelector('#text .container')`
196196
).toHaveBeenWarned()
197197
})
198198

packages/router/__tests__/warnings.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { mockWarn } from './vitest-mock-warn'
99
let component = defineComponent({})
1010

1111
const NEXT_DEPRECATION_MESSAGE =
12-
'The `next()` callback in navigation guards is deprecated. Return the value instead of calling `next(value)`.'
12+
'The `next()` callback in navigation guards is deprecated.'
1313

1414
describe('warnings', () => {
1515
mockWarn()
@@ -289,7 +289,7 @@ describe('warnings', () => {
289289
})
290290
await router.push('/foo')
291291
expect(
292-
'It should be called exactly one time in each navigation guard'
292+
'The "next" callback was called more than once in one navigation guard'
293293
).toHaveBeenWarned()
294294
expect(NEXT_DEPRECATION_MESSAGE).toHaveBeenWarned()
295295
})

packages/router/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
"magic-string": "^0.30.21",
147147
"mlly": "^1.8.2",
148148
"muggle-string": "^0.4.1",
149+
"nostics": "^1.0.0",
149150
"pathe": "^2.0.3",
150151
"picomatch": "^4.0.3",
151152
"scule": "^1.3.0",

packages/router/src/RouterLink.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { routerKey, routeLocationKey } from './injectionSymbols'
2525
import type { RouteRecord } from './matcher/types'
2626
import type { NavigationFailure } from './errors'
2727
import { isArray, isBrowser, noop } from './utils'
28-
import { warn } from './warning'
28+
import { diagnostics } from './diagnostics'
2929
import { isRouteLocation } from './types'
3030
import type {
3131
RouteLocation,
@@ -146,23 +146,7 @@ export function useLink<Name extends keyof RouteMap = keyof RouteMap>(
146146

147147
if (__DEV__ && (!hasPrevious || to !== previousTo)) {
148148
if (!isRouteLocation(to)) {
149-
if (hasPrevious) {
150-
warn(
151-
`Invalid value for prop "to" in useLink()\n- to:`,
152-
to,
153-
`\n- previous to:`,
154-
previousTo,
155-
`\n- props:`,
156-
props
157-
)
158-
} else {
159-
warn(
160-
`Invalid value for prop "to" in useLink()\n- to:`,
161-
to,
162-
`\n- props:`,
163-
props
164-
)
165-
}
149+
diagnostics.VUE_ROUTER_R0050({ to })
166150
}
167151

168152
previousTo = to

packages/router/src/RouterView.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
routerViewLocationKey,
3131
} from './injectionSymbols'
3232
import { assign, isArray, isBrowser } from './utils'
33-
import { warn } from './warning'
33+
import { diagnostics } from './diagnostics'
3434
import { isSameRouteRecord } from './location'
3535

3636
export interface RouterViewProps {
@@ -254,14 +254,6 @@ function warnDeprecatedUsage() {
254254
(parentSubTreeType as Component).name === 'RouterView'
255255
) {
256256
const comp = parentName === 'KeepAlive' ? 'keep-alive' : 'transition'
257-
warn(
258-
`<router-view> can no longer be used directly inside <${comp}>.\n` +
259-
`Use slot props instead:\n\n` +
260-
`<router-view v-slot="{ Component }">\n` +
261-
` <${comp}>\n` +
262-
` <component :is="Component" />\n` +
263-
` </${comp}>\n` +
264-
`</router-view>`
265-
)
257+
diagnostics.VUE_ROUTER_R0060({ comp })
266258
}
267259
}

0 commit comments

Comments
 (0)