-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Make site work with the Cloudflare OpenNext adapter #7383
base: main
Are you sure you want to change the base?
Make site work with the Cloudflare OpenNext adapter #7383
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
b5e1217
to
0463451
Compare
const releaseData = await generateReleaseData(); | ||
|
||
const provideReleaseData = cache(() => releaseData); | ||
const provideReleaseData = cache(() => generateReleaseData()); |
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 made this change because in workerd async operations can't be executed at the top level of a dynamically imported module, and that's what was happening here
(I can add a code comment about it if it'd be helpful)
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.
Sure.
@dario-piotrowicz do we have updates here? 👀 |
Hey @ovflowd 👋 Sorry for keeping the PR lingering, there are a few smaller issues we addressed in our adapter (that I need to reflect here), and also ISR should be coming soon (@vicb can provide more context) Besides that I just need to rebase the PR, the only significant issue remaining should be filesystem access, but I wanted to clarify that with you, I'll drop you a message today to clarify things (PS: I hope the PR is not bothering you 🙇, if you want I can close it and reopen it when we're ready?) |
This is awesome news. Excited to hear from @vicb
I believe we sorted that out on Slack 🖖
Not at all <3 |
542f172
to
2723110
Compare
2723110
to
3481f56
Compare
3481f56
to
f746d5c
Compare
f746d5c
to
4ff9d79
Compare
4ff9d79
to
fac63da
Compare
fac63da
to
d06d8f1
Compare
// if the page number is 0 or something smaller than 1 | ||
providePaginatedBlogPosts(params.category, requestedPage) | ||
: provideBlogPosts(params.category); | ||
const data = await (requestedPage >= 1 |
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 you separate the method call and await to somewhere else? Like add the await
directly on return Response.json(await data, ...)
@@ -92,7 +92,7 @@ const getPage: FC<DynamicParams> = async props => { | |||
// Gets the current full pathname for a given path | |||
const pathname = dynamicRouter.getPathname(path); | |||
|
|||
const staticGeneratedLayout = DYNAMIC_ROUTES.get(pathname); | |||
const staticGeneratedLayout = (await DYNAMIC_ROUTES()).get(pathname); |
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.
One line for await and another for the function call. Also, if DYNAMIC_ROUTES is no longer a constant but an async method, its name should be changed, and it should be moved to another file (in case of DYNAMIC_ROUTES declaration).
@@ -29,7 +29,7 @@ export default async function getDownloadSnippets( | |||
const { default: provideDownloadSnippets } = await import( | |||
'@/next-data/providers/downloadSnippets' | |||
); | |||
return provideDownloadSnippets(lang)!; | |||
return (await provideDownloadSnippets(lang))!; |
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 don't like !
assertions -- can we do something else? :)
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 I didn't add the !
🥹 , not to increase the PR's scope I'd be tempted to keep it as if here and address it in a separate PR?
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.
Gotcha, can we at least separate the await with the return with (!) 🙏
const categoryPosts = posts | ||
async (category: BlogCategory): Promise<BlogPostsRSC> => { | ||
blogData ??= await generateBlogData(); | ||
const categoryPosts = blogData.posts |
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.
const categoryPosts = blogData.posts | |
const categoryPosts = blogData.posts |
|
||
const { categories, posts } = await generateBlogData(); | ||
let blogData: { |
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.
Create a type for this, no inline types.
const blogCategories = await provideBlogCategories(); | ||
|
||
const pages = []; | ||
for (const c of blogCategories) { |
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 use Promise.all here instead of bare for
? So you can use an Array.map and a Promise.all
|
||
const pages = []; | ||
for (const c of blogCategories) { | ||
const categoryPages = (await provideBlogPosts(c)).pagination.pages; |
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.
Separate await from usage
@@ -93,7 +93,7 @@ const getDynamicRouter = async () => { | |||
|
|||
return [...pathnameToFilename.keys()] | |||
.filter(shouldIgnoreStaticRoute) | |||
.concat([...DYNAMIC_ROUTES.keys()]); | |||
.concat([...(await DYNAMIC_ROUTES()).keys()]); |
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.
(Separate await from usage)
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.
So far so good! If there's one keyword for this PR... It'd be await
haha.
To be honest here, can we move these fs helpers from outside this package? I'd appreciate if you could create your own either personal or under the Cloudflare org package for these fs/promises, fs, readLine helpers :)
Just to no add this to our source-code. Or at the very least, another repository or package IDK!
Thank you so much, @dario-piotrowicz for all the effort put in here so far! |
Lighthouse Results
|
update the site application so that it can be build using the Cloudflare OpenNext adapter (`@opennextjs/cloudflare`) and thus deployed on Cloudflare Workers > [!Note] > This is very experimental and currently very slow > it's very much a work-in-progress right now
d06d8f1
to
8b6ed2a
Compare
Thanks for having a look @ovflowd 🫶
Yes, and actually I am waiting a bit before addressing your comments regarding the
That's totally fair, I'll see what I can do 🙂👍 @ovflowd besides the above also note that we still have that partial flash of unstyled contents issue which needs to be addressed 🙂 |
#7531 (comment) it does seem like the adapter is having issues after the rebase, I'll have a look 😓 |
:F: -- sorry, @dario-piotrowicz 🤦 |
This PR applies changes to make it so that the site can be deployed to Cloudflare workers using the open-next Cloudflare adapter
The app does seem to work as intended for the most part:

Deployment URL: https://nodejs-website.web-experiments.workers.dev
Warning
The PR is currently a single commit, I am planning to force push (with
--force-with-lease
) any new changes and keep this a single commit PR for now (so that it's easier to manage and rebase), if that's too annoying problematic for reviewers please let me know and I can just push standard commits if strongly preferredCheck List
npm run format
to ensure the code follows the style guide.npm run test
to check if all tests are passing.npx turbo build
to check if the website builds without errors.