Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dario-piotrowicz
Copy link
Contributor

@dario-piotrowicz dario-piotrowicz commented Jan 2, 2025

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:
Screenshot 2025-01-02 at 19 46 00

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 preferred


Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run npm run format to ensure the code follows the style guide.
  • I have run npm run test to check if all tests are passing.
  • I have run npx turbo build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Mar 3, 2025 0:00am

const releaseData = await generateReleaseData();

const provideReleaseData = cache(() => releaseData);
const provideReleaseData = cache(() => generateReleaseData());
Copy link
Contributor Author

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@ovflowd
Copy link
Member

ovflowd commented Feb 1, 2025

@dario-piotrowicz do we have updates here? 👀

@dario-piotrowicz
Copy link
Contributor Author

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?)

@ovflowd
Copy link
Member

ovflowd commented Feb 16, 2025

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)

This is awesome news. Excited to hear from @vicb

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

I believe we sorted that out on Slack 🖖

(PS: I hope the PR is not bothering you 🙇, if you want I can close it and reopen it when we're ready?)

Not at all <3

// if the page number is 0 or something smaller than 1
providePaginatedBlogPosts(params.category, requestedPage)
: provideBlogPosts(params.category);
const data = await (requestedPage >= 1
Copy link
Member

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);
Copy link
Member

@ovflowd ovflowd Mar 1, 2025

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))!;
Copy link
Member

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? :)

Copy link
Contributor Author

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?

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const categoryPosts = blogData.posts
const categoryPosts = blogData.posts


const { categories, posts } = await generateBlogData();
let blogData: {
Copy link
Member

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) {
Copy link
Member

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;
Copy link
Member

@ovflowd ovflowd Mar 1, 2025

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()]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Separate await from usage)

Copy link
Member

@ovflowd ovflowd left a 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!

@ovflowd
Copy link
Member

ovflowd commented Mar 1, 2025

Thank you so much, @dario-piotrowicz for all the effort put in here so far!

Copy link
Contributor

github-actions bot commented Mar 1, 2025

Lighthouse Results

URL Performance Accessibility Best Practices SEO Report
/en 🟠 82 🟢 100 🟢 100 🟢 91 🔗
/en/about 🟢 100 🟢 100 🟢 100 🟢 91 🔗
/en/about/previous-releases 🟢 100 🟢 100 🟢 100 🟢 92 🔗
/en/download 🟢 90 🟢 100 🟢 100 🟢 91 🔗
/en/blog 🟢 100 🟢 100 🟢 96 🟢 92 🔗

Copy link
Contributor

github-actions bot commented Mar 1, 2025

Unit Test Coverage Report

Lines Statements Branches Functions
Coverage: 90%
88.75% (742/836) 76.1% (242/318) 87.65% (142/162)

Unit Test Report

Tests Skipped Failures Errors Time
182 0 💤 0 ❌ 0 🔥 5.472s ⏱️

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
@dario-piotrowicz
Copy link
Contributor Author

So far so good!

Thanks for having a look @ovflowd 🫶

If there's one keyword for this PR... It'd be await haha.

Yes, and actually I am waiting a bit before addressing your comments regarding the await-related changes because @vicb was working on an aspect of the Cloudflare adapter that might allow us to remove some of these code changes anyways 🤞

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!

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 🙂

@dario-piotrowicz
Copy link
Contributor Author

#7531 (comment) it does seem like the adapter is having issues after the rebase, I'll have a look 😓

@ovflowd
Copy link
Member

ovflowd commented Mar 3, 2025

#7531 (comment) it does seem like the adapter is having issues after the rebase, I'll have a look 😓

:F: -- sorry, @dario-piotrowicz 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants