Skip to content

Commit 343f8a8

Browse files
authored
refactor(router-core,react-router,solid-router,vue-router): Remove long strings from production bundle (#6740)
1 parent 54e6907 commit 343f8a8

File tree

7 files changed

+77
-50
lines changed

7 files changed

+77
-50
lines changed

packages/react-router/src/Matches.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ function MatchesInner() {
9898
<CatchBoundary
9999
getResetKey={() => resetKey}
100100
errorComponent={ErrorComponent}
101-
onCatch={(error) => {
102-
warning(
103-
false,
104-
`The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,
105-
)
106-
warning(false, error.message || error.toString())
107-
}}
101+
onCatch={
102+
process.env.NODE_ENV !== 'production'
103+
? (error) => {
104+
warning(
105+
false,
106+
`The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,
107+
)
108+
warning(false, error.message || error.toString())
109+
}
110+
: undefined
111+
}
108112
>
109113
{matchComponent}
110114
</CatchBoundary>

packages/react-router/src/fileRoute.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ export class FileRoute<
149149
TMiddlewares,
150150
THandlers
151151
> => {
152-
warning(
153-
this.silent,
154-
'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
155-
)
152+
if (process.env.NODE_ENV !== 'production') {
153+
warning(
154+
this.silent,
155+
'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
156+
)
157+
}
156158
const route = createRoute(options as any)
157159
;(route as any).isRoot = false
158160
return route as any
@@ -183,10 +185,12 @@ export function FileRouteLoader<
183185
>
184186
>,
185187
) => TLoaderFn {
186-
warning(
187-
false,
188-
`FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
189-
)
188+
if (process.env.NODE_ENV !== 'production') {
189+
warning(
190+
false,
191+
`FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
192+
)
193+
}
190194
return (loaderFn) => loaderFn as any
191195
}
192196

packages/router-core/src/router.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,12 @@ export class RouterCore<
10371037
TRouterHistory,
10381038
TDehydrated
10391039
> = (newOptions) => {
1040-
if (newOptions.notFoundRoute) {
1041-
console.warn(
1042-
'The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info.',
1043-
)
1040+
if (process.env.NODE_ENV !== 'production') {
1041+
if (newOptions.notFoundRoute) {
1042+
console.warn(
1043+
'The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info.',
1044+
)
1045+
}
10441046
}
10451047

10461048
const prevOptions = this.options
@@ -2702,7 +2704,9 @@ export class RouterCore<
27022704
isDangerousProtocol(redirect.options.href, this.protocolAllowlist)
27032705
) {
27042706
throw new Error(
2705-
`Redirect blocked: unsafe protocol in href "${redirect.options.href}". Allowed protocols: ${Array.from(this.protocolAllowlist).join(', ')}.`,
2707+
process.env.NODE_ENV !== 'production'
2708+
? `Redirect blocked: unsafe protocol in href "${redirect.options.href}". Allowed protocols: ${Array.from(this.protocolAllowlist).join(', ')}.`
2709+
: 'Redirect blocked: unsafe protocol',
27062710
)
27072711
}
27082712

packages/solid-router/src/Matches.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,18 @@ function MatchesInner() {
9494
<CatchBoundary
9595
getResetKey={() => resetKey()}
9696
errorComponent={ErrorComponent}
97-
onCatch={(error) => {
98-
warning(
99-
false,
100-
`The following error wasn't caught by any route! At the very leas
97+
onCatch={
98+
process.env.NODE_ENV !== 'production'
99+
? (error) => {
100+
warning(
101+
false,
102+
`The following error wasn't caught by any route! At the very leas
101103
t, consider setting an 'errorComponent' in your RootRoute!`,
102-
)
103-
warning(false, error.message || error.toString())
104-
}}
104+
)
105+
warning(false, error.message || error.toString())
106+
}
107+
: undefined
108+
}
105109
>
106110
{matchComponent()}
107111
</CatchBoundary>

packages/solid-router/src/fileRoute.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ export class FileRoute<
138138
TMiddlewares,
139139
THandlers
140140
> => {
141-
warning(
142-
this.silent,
143-
'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
144-
)
141+
if (process.env.NODE_ENV !== 'production') {
142+
warning(
143+
this.silent,
144+
'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
145+
)
146+
}
145147
const route = createRoute(options as any)
146148
;(route as any).isRoot = false
147149
return route as any
@@ -173,10 +175,12 @@ export function FileRouteLoader<
173175
>
174176
>,
175177
) => TLoaderFn {
176-
warning(
177-
false,
178-
`FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
179-
)
178+
if (process.env.NODE_ENV !== 'production') {
179+
warning(
180+
false,
181+
`FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
182+
)
183+
}
180184
return (loaderFn) => loaderFn as any
181185
}
182186

packages/vue-router/src/Matches.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,16 @@ const MatchesInner = Vue.defineComponent({
134134
return Vue.h(CatchBoundary, {
135135
getResetKey: () => resetKey.value,
136136
errorComponent: errorComponentFn,
137-
onCatch: (error: Error) => {
138-
warning(
139-
false,
140-
`The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,
141-
)
142-
warning(false, error.message || error.toString())
143-
},
137+
onCatch:
138+
process.env.NODE_ENV !== 'production'
139+
? (error: Error) => {
140+
warning(
141+
false,
142+
`The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,
143+
)
144+
warning(false, error.message || error.toString())
145+
}
146+
: undefined,
144147
children: childElement,
145148
})
146149
}

packages/vue-router/src/fileRoute.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ export class FileRoute<
138138
TMiddlewares,
139139
THandlers
140140
> => {
141-
warning(
142-
this.silent,
143-
'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
144-
)
141+
if (process.env.NODE_ENV !== 'production') {
142+
warning(
143+
this.silent,
144+
'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',
145+
)
146+
}
145147
const route = createRoute(options as any)
146148
;(route as any).isRoot = false
147149
return route as any
@@ -173,10 +175,12 @@ export function FileRouteLoader<
173175
>
174176
>,
175177
) => TLoaderFn {
176-
warning(
177-
false,
178-
`FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
179-
)
178+
if (process.env.NODE_ENV !== 'production') {
179+
warning(
180+
false,
181+
`FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`,
182+
)
183+
}
180184
return (loaderFn) => loaderFn as any
181185
}
182186

0 commit comments

Comments
 (0)