Fix low-severity audit findings across hooks, contexts, and DX#3
Merged
Conversation
Rename PropsContext to ParamsContext for clarity, add throw guards to hooks used outside their provider, rename Router 'options' parameter to 'props', add memory navigation stubs (back/forward/traverseTo/ updateCurrentEntry), add @example JSDoc to all public hooks, fix extractPathname falsy check, remove unused StartTransitionFn export, clean stale oxlintrc ignore patterns, change NotFound from div to h1, and add clearPrefetchCache for cache invalidation. BREAKING CHANGE: PropsContext renamed to ParamsContext in barrel export. StartTransitionFn type removed from TransitionContext. Hooks (useParams, usePathname, useNavigationType, useNavigationSignal) now throw when used outside their provider instead of returning a default value.
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.
Summary
Third and final PR from the deep audit of the router library, addressing all low-severity findings (10 fixes, 10 new tests bringing total to 231).
Naming & Clarity
PropsContexttoParamsContextfor clarity across 5 import sitesoptionstopropsNotFoundcomponent from<div>to<h1>for semantic HTMLDeveloper Safety
useParams,usePathname,useNavigationType, anduseNavigationSignalnow throw descriptive errors when used outside their provider instead of silently returning defaultsuseActiveLinkPropsfor updatedPathnameContextsentinelMemory Navigation Completeness
back(),forward(),traverseTo(),updateCurrentEntry()stubs tocreateMemoryNavigation(throw with descriptive "not supported" messages)Documentation & Exports
@exampleJSDoc blocks to all 8 public hooks that were missing themclearPrefetchCache(matcher)exported function for cache invalidationCode Hygiene
extractPathnamefalsy check (!url→url === null || url === undefined) to allow empty stringsStartTransitionFntype export fromTransitionContextsrc/react-old/**andsrc/old/**patterns from.oxlintrc.jsonBreaking Changes
PropsContextrenamed toParamsContextWhat changed: The exported React context
PropsContextis nowParamsContext.Migration:
Why: The context holds route params, not React props — the old name was misleading.
StartTransitionFntype removedWhat changed: The
StartTransitionFntype is no longer exported fromTransitionContext.Why: It was unused and the module already exports
TransitionFunctionwhich serves the same purpose.Hooks throw outside provider
What changed:
useParams,usePathname,useNavigationType, anduseNavigationSignalnow throw when called outside a<Router>.Migration: No change needed if hooks are already used inside a
<Router>. If you relied on default values outside a provider, wrap the component in a<Router>.Why: Silent defaults masked integration bugs where components were rendered outside the router tree.