Repository navigation
Top level 'use cache' makes functions callable from client? #94286
|
Have just realised that a top level 'use cache' on a file makes all exported async functions callable from the client, similar to 'use server'. This doesn't seem to be documented anywhere and could potentially be a something of a footgun. I guess the security implications are limited so long as you're following the advice to do auth checks in a data access layer, calling But it still seems like the kind of thing which could trip people up and needs to be clearly communicated- i.e. a top level 'use cache' is equivalent to a top level 'use server' so needs the same level of scrutiny to avoid leaking secrets to the client. |
Replies: 1 comment
|
Hi, yes this is possible because they are transformed into a reference. There were some bugs we resolved recently though, for example calling cacheLife, would fail, but that's been fixed. I don't remember why exactly I didn't document this bit. There's more you can do with these of course, and they open up the door to an upcoming feature. I'll review my notes and if everything's clear, drop it in the docs. Here, the left side, is fetching Pokemon w/ Screen.Recording.2025-12-16.at.21.08.04.movReviewing this playground I remember now why I must have not documented this. You still have to do a bit of wiring yourself, I mean, in the sense that we don't have an education story, or recommended pattern just yet... but I can take your point about "accidental imports" - though as mentioned here, they are transformed and the client only ever sees a reference, and within them, you wouldn't necessarily be able to call cookies/headers, except for the private cache, unless you wrap them in yet another Server Function, |
Hi, yes this is possible because they are transformed into a reference.
There were some bugs we resolved recently though, for example calling cacheLife, would fail, but that's been fixed.
I don't remember why exactly I didn't document this bit. There's more you can do with these of course, and they open up the door to an upcoming feature. I'll review my notes and if everything's clear, drop it in the docs.
Here, the left side, is fetching Pokemon w/
use cachefrom the client, but not the JSON, instead it returns the JSX already.Screen.Recording.2025-12-16.at.21.08.04.mov
Reviewing this playground I remember now why I must have not documented this. You still have to do a bit of w…