Repository navigation
Typed path nodes skip renderPath in navigate() and redirect() #672
everton-dgn
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I maintain an SSR app with canonical routes such as
/aboutand public URLs such as/en/aboutand/pt/about. One router serves all requests.transformUrlhandles matching, andhistory.utils.renderPathhandles outgoing hrefs. With a prefix adapter, a typed node and its called form go to different places.This example hard-codes the locale to
en, on@solidjs/router2.0.0-next.38:Mount at
/en/aboutand try each control from a fresh load. The link and Called button reach/en/other; Node reaches/other. Calling the node or usingString(Router.paths.other)preserves the prefix in bothnavigate()and action redirects. Those forms also pass TypeScript checking.navigate()deliberately reads the node's logicalHREFvalue, while calling or stringifying it appliesrenderPath. Hash history handles its prefix in its parser and writer; this adapter inherits the browser history writer. The separateredirect()helper in@solidjs/webalso readsHREF: a bare node loses the prefix at runtime. That call currently fails typechecking with TS2345, so I kept it out of the example.Is bypassing
renderPaththe intended contract for typed nodes with adapters like this? The README shows bare nodes in navigation. A note there could explain when to call the node, or the adapter contract could make the two forms agree. That seems worth settling before adding a reverse transform, given #465. I'd keepuseLocation()aligned with the browser URL, as discussed in #466.A
baseresolved once per server request and once per client mount could be an alternative API. Unlike the reactive change in #64, it would stay fixed during navigation. It would need to preserve shared compilation and account for the base captured bypaths. There is a separate bug to address first: withbase: "/pt", bothnavigate(Router.paths.x)andnavigate(Router.paths.x())reach/pt/pt/x.I tested these cases in Vitest/jsdom against
dc1e0b0, withsolid-jsand@solidjs/web2.0.0-rc.14. In concurrent SSR tests on one router, arenderPathreadinggetRequestEvent().request.urlproduced/en/aboutand/pt/aboutand kept the prefix inuseLocation(). The example passes typechecking. Hydration and a request-scoped base implementation remain untested.All reactions