diff --git a/packages/react-router/src/link.tsx b/packages/react-router/src/link.tsx index 0ce9b25c94..fc33e6b594 100644 --- a/packages/react-router/src/link.tsx +++ b/packages/react-router/src/link.tsx @@ -166,9 +166,6 @@ export function useLinkProps< const router = useRouter() const innerRef = useForwardedRef(forwardedRef) - // Determine if we're on the server - used for tree-shaking client-only code - const _isServer = isServer ?? router.isServer - const { // custom props activeProps, @@ -220,7 +217,9 @@ export function useLinkProps< // // Note: `location.hash` is not available on the server. // ========================================================================== - if (_isServer) { + // The expression must stay inlined in the `if` so bundlers fold the + // browser-build constant `isServer = false` and drop this server block. + if (isServer ?? router.isServer) { const safeInternal = isSafeInternal(to) // If `to` is obviously an absolute URL, treat as external and avoid diff --git a/packages/react-router/src/useRouterState.tsx b/packages/react-router/src/useRouterState.tsx index 1e281645af..f3fbb2ad6e 100644 --- a/packages/react-router/src/useRouterState.tsx +++ b/packages/react-router/src/useRouterState.tsx @@ -56,8 +56,9 @@ export function useRouterState< // During SSR we render exactly once and do not need reactivity. // Avoid subscribing to the store (and any structural sharing work) on the server. - const _isServer = isServer ?? router.isServer - if (_isServer) { + // The expression must stay inlined in the `if` so bundlers fold the + // browser-build constant `isServer = false` and drop this server block. + if (isServer ?? router.isServer) { const state = router.stores.__store.get() as RouterState< TRouter['routeTree'] > diff --git a/packages/solid-router/src/useRouterState.tsx b/packages/solid-router/src/useRouterState.tsx index bf68d81ed4..382e35d2d2 100644 --- a/packages/solid-router/src/useRouterState.tsx +++ b/packages/solid-router/src/useRouterState.tsx @@ -33,8 +33,9 @@ export function useRouterState< // During SSR we render exactly once and do not need reactivity. // Avoid subscribing to the store on the server since the server store // implementation does not provide subscribe() semantics. - const _isServer = isServer ?? router.isServer - if (_isServer) { + // The expression must stay inlined in the `if` so bundlers fold the + // browser-build constant `isServer = false` and drop this server block. + if (isServer ?? router.isServer) { const state = router.stores.__store.get() as RouterState< TRouter['routeTree'] > diff --git a/packages/vue-router/src/useRouterState.tsx b/packages/vue-router/src/useRouterState.tsx index 13b6f85236..7d3d536f57 100644 --- a/packages/vue-router/src/useRouterState.tsx +++ b/packages/vue-router/src/useRouterState.tsx @@ -39,9 +39,9 @@ export function useRouterState< // During SSR we render exactly once and do not need reactivity. // Avoid subscribing to the store on the server since the server store // implementation does not provide subscribe() semantics. - const _isServer = isServer ?? router.isServer - - if (_isServer) { + // The expression must stay inlined in the `if` so bundlers fold the + // browser-build constant `isServer = false` and drop this server block. + if (isServer ?? router.isServer) { const state = router.stores.__store.get() as RouterState< TRouter['routeTree'] >