-
-
Notifications
You must be signed in to change notification settings - Fork 705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make react router as peer dep instead of dependency #3001
base: main
Are you sure you want to change the base?
Conversation
getting latest main
☁️ Nx Cloud ReportCI is running/has finished running commands for commit e98f51c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
start cannot be used without router, so a peer dependency is not expressing the correct relationship. |
May be we can expose all functions like createRouter from start then? By reexporting I mean. |
this seems like a workaround for some bundler issues. what's the proper solution here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have it documented pretty much everywhere, that start is meant to be used with router, I think its fine to move it to peerDeps.
@@ -134,7 +134,6 @@ | |||
}, | |||
"dependencies": { | |||
"@tanstack/react-cross-context": "workspace:^", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worth checking out, whether we are actually using the react-cross-context
package and possibly remove it.
I came across this while debugging #3002
Some package managers/resolvers in certain cases, load different downstream packages for different imports.
For instance, in tanstack/start quick starter app, we import both
@tanstack/start
and@tanstack/router
.@tanstack/router
is imported in user application(See Getting Started) as well in@tanstack/start
. In one place the resolver may resolve to a different module than in the other places.deno, for instance resolves
@tanstack/react-router
in user application to node_modules/.deno/@TanStack[email protected]_1 and@tanstack/react-router
in@tanstack/start
to node_modules/.deno/@TanStack[email protected]This causes a null router value to be returned by useRouterState() and the following logs:
when the
<Outlet />
code ultimately fetches context.In other words, the module that hung the context up was in
ssr.tsx
viacreateStartHandler
/StartServer
wasnode_modules/.deno/@[email protected]_1
(because resolver resolved to that module)While, the code uses(and gets from resolver)
node_modules/.deno/@[email protected]
pnpm/deno/bun/yarn all three can resolve to different modules this way.
Related issues:
#3002 - deno issue
#2594 - refers to bun and pnpm
#2540 - refers to pnpm and yarn
#1692 - doesn't mention the package manager used, but seems to indicate a similar issue.
I have fixed only the react-router issue for now. But if people used
@tanstack/react-cross-context
directly in their code, then they will see this issue there as well.This means that potentially all the libraries in tanstack start/router should be appropriately set as peer dependencies instead of dependencies as a matter of best practice(because unlike a typical monorepo tanstack router packages should be independently usable as well). I will leave it for @tannerlinsley if/when he wants to do these changes, if he accepts this fix.
At the very least,
@tanstack/react-cross-context
should be declared as peer dependency in@tanstack/router
as it is the container where we hang up the context(a singleton). Otherwise people will use it in their code and end up with two different contexts and will end up hitting their heads against the wall on why their context is empty in some part of the code while it is correctly obtained in other places(or worse they will have some 10 contexts).The potential packages can be seen by dependency tree where this practice should apply:
BTW this issue can show up in node as well if npm installs nested dependencies. I am not 100% sure on the module resolution logic of current npm but I believe at least older npm versions used to do this.