-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Hello ToolsPlus team,
First of all, thank you for creating and maintaining this very useful library for the Forge ecosystem.
After a long debugging session, we've identified a fundamental issue in how @toolsplus/forge-trpc-link handles its tRPC dependencies, which leads to unexpected behavior and very subtle type errors.
The Problem
The @toolsplus/forge-trpc-link library (and likely other packages in the monorepo) includes the @trpc/* libraries as direct dependencies in its package.json instead of as peerDependencies.
Consequences
This causes several critical problems in a project consuming the library:
-
Version Conflict and Duplication: This causes two versions of
@trpc/clientto be installed in the final project. For context, our project uses the latest version of tRPC (v11.4.3), while the version bundled withforge-trpc-linkappears to be an older, fixed version. This unnecessarily increases the final bundle size. -
instanceofChecks Fail: This is the most critical issue. TheTRPCClientErrorimported in my application is not the same class as theTRPCClientErrorhandled by the link internally. As a result, any type check likeerror instanceof TRPCClientErrorwill always return false. -
Unexpected Behavior: We believe this type conflict is the root cause of why
@trpc/react-queryfails to recognize the error coming from the link as a valid instance of "its"TRPCClientError. As a safety mechanism, it wraps the original error in a new one, assigning the original to the.causeproperty. This forces developers to implement complex workarounds in the application layer to normalize errors.
Expected Behavior
The library should use the same instance and version of the @trpc/* libraries as the host project. This is achieved by declaring them as peerDependencies.
Proposed Solution
The solution is to move all @trpc/* dependencies from the dependencies object to the peerDependencies object in the package.json for the @toolsplus/forge-trpc-link package.
This change would resolve the type conflicts, reduce the final bundle size, and make the library behave predictably and consistently with the tRPC ecosystem.
Thank you for your time and for your excellent work on this library!