Router seeding from the server: routers module, announceRoutes, drop filesystem-routing - #4
Merged
Conversation
prerender-crawler/routers (no Node imports, for application server code): tanstackRouterPages(router) reads a TanStack instance's routesByPath; solidRouterPages(router | routes) walks a Solid Router 2 definition tree; announcePages(request, headers, paths) puts them on the hint header when the request is the crawler's. Tested against real @tanstack/router-core and @solidjs/router instances (dev deps) so drift in either shape shows up here first. Co-authored-by: Cursor <cursoragent@cursor.com>
fileRoutePages, staticRoutePaths, and the plugin's fileRoutes option walked a route directory at build time and re-derived its path rules — a copy of another package's semantics, blind to routes defined in code, and useless to a crawl that never sees the project's disk (the CLI against a running server). The server's router announcing its pages on the hint header replaces all of it. filesystem-routing is no longer a peer; the router packages join as dev deps for the routers tests. Co-authored-by: Cursor <cursoragent@cursor.com>
Server half reads the ambient request event and, for the crawler's request, writes the router's static pages to the response's hint header; client half is a no-op. The example root calls it. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
Replaces build-time route-directory scanning with the server declaring its own pages.
Why.
fileRoutePageswalkedsrc/routesat build time and re-derivedfilesystem-routing's path rules — a copy of another package's semantics, blind to routes defined in code (Solid Router config routes, TanStack Router), and useless to a crawl that never sees the project's disk (the CLI against a running server). The thing that actually knows which pages exist is the router the app built for the request, and the crawler already has the channel for a server to say so: thex-prerenderhint header.prerender-crawler/routers(no Node imports — for application server code):tanstackRouterPages(router)— from a TanStack instance's publicroutesByPath(one core for React/Solid/Vue flavors). Skips$segments (params, splats,{-$optional}) and layouts without an index.solidRouterPages(router | routes, { base? })— walks a Solid Router 2createRouterinstance or definition tree. Leaves and indexes, aliases expanded, pathless layouts joined through,:param/:opt?/*splatskipped; lazy children left to link crawling (enumerating them would load modules during a render).announcePages(request, headers, paths)— writes the header only for the crawler's request.Both helpers are tested against real
@tanstack/router-coreand@solidjs/routerinstances (dev deps), so drift in either shape shows up in our CI.@solidjs/prerender:announceRoutes(Router)— one line in the app root; reads the ambient request event on the server, no-op in the browser.Removed:
fileRoutePages,staticRoutePaths, the plugin'sfileRoutesoption, and thefilesystem-routingpeer.Verified: 65 crawler + 23 solid tests; example build renders the same 5 pages; and with
--no-linksthe CLI renders exactly/+ the announced/posts(dynamic/posts/:slugcorrectly left to links), proving the header path end to end.Made with Cursor