feat(nextjs): functional App Router adapter (replaces stub)#30
Open
Priyans-hu wants to merge 3 commits into
Open
feat(nextjs): functional App Router adapter (replaces stub)#30Priyans-hu wants to merge 3 commits into
Priyans-hu wants to merge 3 commits into
Conversation
Replace the stub that threw "not yet implemented" with a working
adapter mirroring the React Router adapter shape.
- useNextNavigate(): wraps next/navigation useRouter for command actions
- useNextPrefetch(): exposes router.prefetch
- useNextCommandRoutes(routes): registers a sitemap as command items
with router.push wired into each command's action
- <NextCommandRoutes routes={...} />: HOC variant
- usePrefetchOnHover(): factory for hover-prefetch handlers
- Accepts NextRouteLike[], Sitemap, or { routes: [...] } as input
- Optional prefetchOnMount, defaultGroup, transform options
next is added as an optional peer dep alongside react/react-dom.
Both cmdk-engine/adapters/nextjs and cmdk-engine/nextjs entry points
are exported from package.json. Bundle is ~4.2KB ESM.
Mock next/navigation useRouter to test: - useNextNavigate calls router.push (and router.replace when replace:true) - useNextPrefetch calls router.prefetch - useNextCommandRoutes registers commands derived from input - prefetchOnMount calls prefetch for every route on mount - transform option overrides derived defaults - defaultGroup falls in when no group is set - <NextCommandRoutes /> HOC delegates to the hook - usePrefetchOnHover returns a handler factory 17 new tests, total moves 196 -> 213.
- Add a "Next.js (App Router) Integration" section between "React Router Integration" and "RBAC". - Update package entry point table and adapter quick-reference. - Add changeset entry under .changeset/nextjs-adapter.md as a minor bump for cmdk-engine.
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.
The Next.js adapter in
src/adapters/nextjs/index.tspreviously threw "not yet implemented", despite README + keywords + comparison table claiming Next.js support. This PR ships a real adapter that mirrors the React Router adapter's shape.What's included
useNextNavigate()— wrapsnext/navigationuseRouterfor command actions (supportsreplaceandscrolloptions)useNextPrefetch()/usePrefetchOnHover()— hover prefetch viarouter.prefetch(href)useNextCommandRoutes(routes, options?)/<NextCommandRoutes routes={...} />— registers build-time-scanned routes as commands; each command'sactioncallsrouter.push(href)nextdeclared as an optional peer dep (alongsidereact/react-dom) — not bundledcmdk-engine/nextjs(aliascmdk-engine/adapters/nextjs)How to use
The hook accepts the
Sitemapproduced bycmdk-engine scan, aSitemapRoute[], hand-authoredNextRouteLike[], or any{ routes: [...] }-shaped object. Options:prefetchOnMount,defaultGroup,transform.Tests
+17 tests under
tests/adapters/nextjs.test.tsxmockingnext/navigation. Total moves 196 → 213. Lint, typecheck, test, and build all pass.Verification
Migration
None — adapter was non-functional before.