-
Notifications
You must be signed in to change notification settings - Fork 130
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
implement custom cache handler logic #606
base: main
Are you sure you want to change the base?
implement custom cache handler logic #606
Conversation
|
🧪 Prereleases are available for testing 🧪 @cloudflare/next-on-pagesYou can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/7624406804/npm-package-next-on-pages-606 @cloudflare/eslint-plugin-next-on-pagesYou can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/7624406804/npm-package-eslint-plugin-next-on-pages-606 |
3209dd8
to
ad9cdbf
Compare
859f576
to
5b98363
Compare
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.
LGTM - I left a bunch of nits but nothing blocking.
(Caveat - I have not actually tried this out locally!!)
|
||
test('processing a next.config.js file exporting a function', async () => { | ||
mocks.nextConfigJsFileExists = true; | ||
mocks.nextConfigMjsFileExists = false; |
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.
What happens if both files exist??
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.
If both files exist Next.js picks the first/default one (next.config.js
) and ignored the mjs one
(source)
We also do the same:
const configFilePath = | |
(await getConfigFilePath('js')) || (await getConfigFilePath('mjs')); |
72fb43d
to
95cf34b
Compare
this includes: - refactoring existing logic so that it uses the incrementalCache class concept that Next.js also uses (so that we alight the two implementations) - reading the user next.config.(m)js file and create a custom cache handler and collecting the cache handler referenced in the incrementalCacheHandlerPath config - building the custom cache handler instead of the built-in ones in case one was indeed provided by the user
2667560
to
de839e0
Compare
entry = { | ||
isStale, | ||
revalidateAfter, | ||
value: null, | ||
}; | ||
|
||
if (cacheData) { | ||
entry.value = cacheData.value; | ||
entry.age = age; | ||
} else { | ||
await this.set(cacheKey, entry.value, ctx); | ||
} |
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.
Note: I think this is incorrect
if cacheData
is falsy we end up setting the cacheKay
value to null
here, which generates the error mentioned in #606 (comment)
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.
But the exact same happens in the Next.js code... 🤔
This will be awesome if released!! |
resolves #529
resolves #628
Example app: https://github.com/dario-piotrowicz/next-geolocation-pages
(application using a supabase custom cache handler)
Vercel deployment: https://next-geolocation-pages-glqcs9da0-dario-piotrowicz.vercel.app/
Pages deployment: https://8e0d4e38.next-geolocation-pages.pages.dev/
TODO:
(solved, see: dario-piotrowicz/next-geolocation-pages@a4eb865)
next.config.js
files are correctly handled, this means function exports (as mentioned here and .mjs extensions)(tested and everything seems to be in order, see: dario-piotrowicz/next-geolocation-pages@ac3f05e)
TODO as a follow up, not to scope-creep this PR: