-
Notifications
You must be signed in to change notification settings - Fork 86
feat: refresh hooks api implementation #1950
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
Conversation
…gin-nextjs into rs/refresh-hooks-poc
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-edge-middleware ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for nextjs-plugin-custom-routes-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
…gin-nextjs into rs/refresh-hooks-api
@@ -47,6 +47,10 @@ export const generateFunctions = async ( | |||
await ensureDir(join(functionsDir, functionName)) | |||
await writeFile(join(functionsDir, functionName, `${functionName}.js`), apiHandlerSource) | |||
await copyFile(bridgeFile, join(functionsDir, functionName, 'bridge.js')) | |||
await copyFile( | |||
join(__dirname, '..', '..', 'lib', 'templates', 'server.js'), | |||
join(functionsDir, functionName, 'server.js'), |
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.
Can we get some comments on why we're copying this file? (This whole functions.ts file could use those tbh hah, but I won't put that on you)
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.
yep, i totally agree! i don't know enough about some of the functions in there to comment it all, but i've added comments to generateFunctions()
in fd32f38
|
||
// Normalize a data route to include the locale prefix and remove the index suffix | ||
export const localizeDataRoute = (dataRoute: string, localizedRoute: string): string => { | ||
if (dataRoute.endsWith('.rsc')) return dataRoute |
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.
.rsc
should probably be a constant at this point
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'm not certain about this - there's a bunch of strings in that function that we could make into constants - but they are unlikely to change and i think it helps readability to know what they are in that context, especially since specifics like whether they have a .
or a /
are important with that string wrangling
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.
Fair!
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.
🎉 Yayy Rob!
This is so exciting! Thank you Netlify team! |
I'm wondering how to update the Netlify Docs for Next.js On-Demand ISR. Any suggestions? |
Summary
This PR incorporates the work of the refresh hooks PoC #1937 and integrates it with the new refresh hooks API endpoint to implement on-demand revalidation with the Next Runtime.
The approach is to subclass the Next.js Server with an implementation that overrides
getRequestHandler()
so that we can provide our own handler that checks for the existence of anx-prerender-revalidate
header, which gets sent during a call tores.revalidate()
.Once we detect the header we can handle the request by, first, allowing the original handler to complete (to use Next itself as the source of truth for error handling) and then calling our own
netlifyRevalidate()
function, which parses theprerender-manifest.json
to retrieve all paths associated with a route (eg. the data route or RSC route), normalizes them (e.g. index routes and locales), computes any dynamic params, and passes them as the body of an API call to therefresh_on_demand_builders
endpoint.Errors specific to the Netlify revalidation are logged to the serverless function logs and then thrown in the same way as the Next.js handler does.
Test plan
UPDATE: Add a
?select={number}
query to theapi/revalidate
route to test revalidation of other route types. Details here: https://github.com/netlify/next-runtime/pull/1950/files#diff-77d2214b5448bd28b99f8d9394345fc60030c657bd155778f461295932d54098Unit and e2e tests are included.
Closes netlify/pod-ecosystem-frameworks#391