-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(next/app-dir): contextCache
to control context values to add to cacheTag
#5537
base: next
Are you sure you want to change the base?
Conversation
This change allows a user to specify `contextCache` method in the `experimental_nextCacheLink`, which lets one select the values from the context that should be considered when a `cacheTag` is generated. It also changes the way `cacheTag` is generated, taking care of the fact that the `cacheTag` cannot be longer then 256 characters, thus instead of stringifying input values, it will form a sha-256 hash of those. Implements trpc#5455
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
@dalechyn is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
Doesn't serve any benefit since `server-invoker` exists.
I haven't found a way to mock `next-auth` from playwright so instead, I'm setting different extra headers that go into the `cacheContext` fn.
|
||
/** | ||
* This client invokes procedures directly on the server without fetching over HTTP. | ||
*/ | ||
export const api = experimental_createTRPCNextAppDirServer<typeof appRouter>({ | ||
config() { | ||
return { | ||
createContext: () => createContext('invoke'), | ||
contextSelector: (ctx, callOpts) => { |
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.
I think this example should show a "private by default" and opt-in to sharing cache for specific procedures thst doesnt have sensitive data
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.
Good thoughts, will implement
if (typeof window !== 'undefined' && window.AbortController) { | ||
return window.AbortController; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain |
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.
???
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.
pnpm lint-fix
did that, i undoed the changes and a workflow applied formatting once again π΅βπ«
if (typeof window !== 'undefined' && window.TextDecoder) { | ||
return new window.TextDecoder(); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain |
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.
???
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.
packages/next/src/app-dir/server.ts
Outdated
|
||
const ctx = await config.createContext(); | ||
runtime.ctx = ctx; | ||
runtime.cacheTagSeparators = config.contextSelector?.(ctx, callOpts) ?? []; |
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.
I dont think we can cache this anymore when it's procedure-specific, it should be invoked every call i think
if (callOpts.path[0] === 'privateGreeting') | ||
return [ctx.session?.user.id, ctx._userIdMock]; | ||
return []; | ||
if (!['privateGreeting'].includes(callOpts.path[0])) return []; |
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.
a comment would be nice - i don't know if even i would know what this does if i revisit this example in a month or 2 ;)
packages/next/src/app-dir/server.ts
Outdated
const config = opts.config(); | ||
return createTRPCUntypedClient(config); | ||
}); | ||
const client = createTRPCUntypedClient(config); |
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.
this can still be deduped as it was before, no?
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.
done!
pnpm-lock.yaml
Outdated
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.
revert lock changes
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.
Changes overall looks good to me.
While we are considering deprecating all of this stuff in favor of the experimental_caller() approach (#5589), we could merge this in the interrim after resolving the few nits I left
Dup of #5458
π― Changes
What changes are made in this PR? Is it a feature or a bug fix?
β Checklist