Skip to content

fix: remove more internal exports - #5101

Closed
KATT wants to merge 35 commits into
nextfrom
housekee-again
Closed

KATT wants to merge 35 commits into
nextfrom
housekee-again

Conversation

@KATT

@KATT KATT commented Nov 24, 2023 •

Copy link
Copy Markdown
Member

Closes #

🎯 Changes

Remove a bunch of external imports

ref #3496:

[ ] Look through @internal-marked types/fns and see if we can avoid exposing them in the bundle altogether

  • Overall, we should try to get rid of export * from X and have index files that only export exactly what we want
  • Once we've done this, we need to look at third party libraries using trpc and make sure that they have a migration path - maybe we start exporting some stuff specifically for plugins

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

@vercel

vercel Bot commented Nov 24, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-prisma-starter ❌ Failed (Inspect) Dec 23, 2023 10:48pm
og-image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Dec 23, 2023 10:48pm
trpc-next-app-dir ❌ Failed (Inspect) Dec 23, 2023 10:48pm
www ❌ Failed (Inspect) Dec 23, 2023 10:48pm

@github-actions

github-actions Bot commented Nov 24, 2023 •

Copy link
Copy Markdown
Contributor

Diagnostics Comparison

Details

Numbers

Metric PR next
Files 750 751 (πŸ”½πŸŸ’ -1)
Lines of Library 40,241 40,241 (βž– 0)
Lines of Definitions 118,672 118,674 (πŸ”½πŸŸ’ -2)
Lines of TypeScript 4,867 4,867 (βž– 0)
Lines of JavaScript 0 0 (βž– 0)
Lines of JSON 0 0 (βž– 0)
Lines of Other 0 0 (βž– 0)
Identifiers 174,321 174,296 (πŸ”Ί 25)
Symbols 108,780 108,767 (πŸ”Ί 13)
Types 89 89 (βž– 0)
Instantiations 0 0 (βž– 0)
Memory used 173,983 168,462 (πŸ”Ί 5,521)
Assignability cache size 0 0 (βž– 0)
Identity cache size 0 0 (βž– 0)
Subtype cache size 0 0 (βž– 0)
Strict subtype cache size 0 0 (βž– 0)

Timings and averages

Metric PR next
max (s) 4.994 4.903 (πŸ”Ί 0.09)
min (s) 4.863 4.829 (πŸ”Ί 0.03)
avg (s) 4.932 4.866 (πŸ”Ί 0.07)
median (s) 4.933 4.864 (πŸ”Ί 0.07)
length 21 21 (βž– 0)
unstable timings

Unstable

Timings are not reliable in here

Metric PR next
I/O Read time 0.04 0.04 (βž– 0)
Parse time 0.74 0.74 (βž– 0)
ResolveTypeReference time 0.03 0.03 (βž– 0)
ResolveModule time 0.13 0.12 (πŸ”Ί 0.01)
ResolveLibrary time 0.02 0.02 (βž– 0)
Program time 1.09 1.07 (πŸ”Ί 0.02)
Bind time 0.43 0.43 (βž– 0)
Total time 1.52 1.51 (πŸ”Ί 0.01)

@@ -1,4 +1,4 @@
import { AnyRouter } from '@trpc/server';
import { AnyRouter } from '@trpc/server/unstableInternalsExport';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be public imo

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename it to TRPCRouter?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. rename it
  2. deprecate and alias old

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea sounds good

import { transformResult } from '../shared/transformResult';
import {
AnyRouter,
inferRouterError,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can change it if people ask for it

import { observable } from '@trpc/server/observable';
import {
AnyRouter,
callProcedure,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a public way of doing this as it's nice for RSC

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you use router.createCaller() for that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, we should deprecate router.createCaller and create a createCaller(x) instead

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createCaller doesnt play very nice as a client if you have async context.

createTRPCClient with custom link using callProcedure is the best I've found

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an example of this within the tRPC repo somewhere so I can understand it better?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows pretty well why it's not the best ergonomics when using createCaller.

https://github.com/t3-oss/create-t3-turbo/blob/eae39060ee1ea1bad06842c3a3ce7a80463405c5/apps/nextjs/src/trpc/server.ts#L63-L72

The two accomplishes the exact same thing but the client doesn't require nested awaits.

We could probably make something that's even better though, like allowing createCaller to accept a function, and then that'd be called at the same time as the actual procedure. Since you can wrap it in cache, it'd still be de-duped.

const trpc = appRouter.createCaller(createContext);

const post = await trpc.post.all();

@juliusmarminge juliusmarminge Dec 15, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although you'd still miss things like having the loggerLink etc, maybe we want a like... client but that doesn't have the .query or .mutation at the end, since that has no effect when you're not doing http requests.

Comment on lines +20 to +26
export type {
AnyRouter as AnyTRPCRouter,
/**
* @deprecated use `AnyTRPCRouter` instead
*/
AnyRouter,
} from './core';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs cleanup

@KATT KATT mentioned this pull request Nov 24, 2023
12 of 22 tasks
KATT added 3 commits December 15, 2023 18:18
# Conflicts:
#	packages/client/src/links/wsLink.ts
# Conflicts:
#	.wip/changes.md
#	packages/client/src/TRPCClientError.ts
#	packages/react-query/src/shared/hooks/createHooksInternal.tsx
#	packages/tests/server/___testHelpers.ts
@KATT KATT mentioned this pull request Dec 23, 2023
1 task done
@KATT

KATT commented Dec 23, 2023

Copy link
Copy Markdown
Member Author

I think #5101 is a better approach - closing, might re-open later

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

This branch had an error being deployed

4 failed and 1 active deployments
Preview – www β€” d5a182b8 Deployed Dec 23, 2023 by vercel[bot]
Preview – og-image β€” d5a182b8 Deployed Dec 23, 2023 by vercel[bot]
Preview – todomvc β€” d5a182b8 Deployed Dec 23, 2023 by vercel[bot]
Preview – trpc-next-app-dir β€” d5a182b8 Deployed Dec 23, 2023 by vercel[bot]
Preview – next-prisma-starter β€” d5a182b8 Deployed Dec 23, 2023 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants