Reorganize client router modules (#97402)
Pure structural refactor, no behavior changes. This continues some of the clean-up work I've been doing in the client router now that more of the implementation has settled, post-Segment Cache and Instant Navigations. I have two primary motivations here. The first is purely maintainability. The current module structure is a mess, and the naming is misleading when browsing the codebase for the first time. The second motivation is to prepare for an upcoming rewrite of the router queue. There will likely be two simultaneous implementations for a while as the new one settles, so it's extra important the interface into the router queue is well-defined. I want the fork between the two worlds to be as clean as possible. This is a similar approach to the one I took when rewriting the prefetching implementation. Some of the key name changes: - ppr-navigations.ts → render-tree.ts. This module's responsibility is to create the tree that gets passed into React for rendering, currently called the CacheNode tree. I considered renaming it to cache-node.ts, but I kept it more generic because I have plans to refactor that type soon. - segment-cache/navigation.ts → app-router-state.ts. This module's responsibility is to compute the next AppRouterState given inputs. It does perform network requests, but it's conceptually a "pure" operation. It doesn't deal with any of the router queueing logic. This is the most reducer-y of the code that still exists, and along with render-tree.ts, it will remain mostly shared between the old and new state machine implementations. - navigator.ts. This is a new module I created to act as the single entry point for router-level operations: push, replace, navigate, traverse, restore, refresh, hmrRefresh. This is the primary place where we'll fork the old and new queue implementations. It's also how we'll ensure the inactive implementation gets dead-code-eliminated properly while the two implementations live side-by-side.
Showing
Please
register
or
sign in
to comment