-
Notifications
You must be signed in to change notification settings - Fork 573
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
chore: better DX around for @cacheable #10847
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
hasNoCacheParamPresent, | ||
hasPersonalizedArguments, | ||
isRequestCacheable, | ||
SKIP_CACHE_ARGUMENTS, | ||
} from "app/system/relay/helpers/cacheHeaderMiddlewareHelpers" | ||
import { GraphQLRequest } from "app/system/relay/middlewares/types" | ||
import { Middleware } from "react-relay-network-modern" | ||
|
@@ -16,18 +17,34 @@ export const shouldSkipCDNCache = (req: GraphQLRequest) => { | |
// - a known personalized argument is present in the query (for example `include_artworks_by_followed_artists`) | ||
// - nocache param is present in the url | ||
|
||
if (req.cacheConfig?.force === true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this down since it will be covered by the default case anyway |
||
return true | ||
} | ||
|
||
if (isRequestCacheable(req)) { | ||
if (req.cacheConfig?.force === true) { | ||
if (__DEV__) { | ||
console.warn( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use info here? These warnings in the simulators/emulators are pretty annoying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried both actually but they both seems equally ugly 🥲 except that the warn shows the count better Screen.Recording.2024-09-26.at.10.38.46.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😢 then I'd vote only to console.log, these bubbles are bad for DX because they block the screen and all the time we have to close them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that console.warns can be annoying, but that's only if you can't dismiss them or don't know why they're occuring. Here, the action item should be clear, for example you need to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, after a 2nd thought I'm fine with it, it should really pester someone in this case, 👍 for the .warn then |
||
"You are setting force: true on a cacheable request, CDN cache will be ignored." | ||
) | ||
} | ||
return true | ||
} | ||
|
||
const url = getCurrentURL() | ||
if (url && hasNoCacheParamPresent(url)) { | ||
if (__DEV__) { | ||
console.warn( | ||
"You are setting nocache param in the url on a cacheable request, CDN cache will be ignored." | ||
) | ||
} | ||
// Don't use CDN cache if the url has the nocache param | ||
return true | ||
} | ||
|
||
if (hasPersonalizedArguments(req.variables)) { | ||
if (__DEV__) { | ||
console.warn( | ||
"You are setting a personalized argument on a cacheable request, CDN cache will be ignored.\nList of personalized arguments: ", | ||
SKIP_CACHE_ARGUMENTS.join(", ") | ||
) | ||
} | ||
// Don't use CDN cache if the query has a personalized argument | ||
return true | ||
} | ||
|
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.
the query params where not present in the helper so I added them here