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

OpenNext V3 #402

Merged
merged 107 commits into from
May 3, 2024
Merged

OpenNext V3 #402

merged 107 commits into from
May 3, 2024

Conversation

conico974
Copy link
Contributor

This PR is for OpenNext V3.

There is one remaining thing that may still need some changes it's the experimentalBundledNextServer options that is broken in Next 14.2 and it might be hard to make it work again. There is 2 way to handle this, we could just deprecate the options ( maintaining this could become an absolute nightmare), or we could keep it as is (it's experimental after all) and fix it for new versions when we get time.

One other things is that the e2e tests uses a custom CDK implementation, we may want to move to Ion, or we could keep the cdk implementation as some sort of reference implementation. (this is probably something we can do later)

I know that this will be very hard to properly review such a big PR, feel free to ask if you need some information on anything either here or on discord.

Last things, i think we should not squash merge this PR, and we probably want to manually edit the changelog in the Version Packages PR as well.

Copy link

changeset-bot bot commented Apr 11, 2024

🦋 Changeset detected

Latest commit: 52641c1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
open-next Major
app-pages-router Patch
app-router Patch
tests-unit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 11, 2024

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

Name Status Preview Comments Updated (UTC)
open-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 1:16pm

@khuezy
Copy link
Contributor

khuezy commented Apr 11, 2024

Nice! There's a lot to review and I'll likely miss a bunch.

@conico974
Copy link
Contributor Author

Nice! There's a lot to review and I'll likely miss a bunch.

Yeah don't worry, worst case scenario we can still fix things later if needs be.
We need to stop having 2 separate versions of OpenNext, it's becoming a pain to manage. I've given up doing rebase in V3, because it was too much work to rebase like 80 commits every time. Also a lot of the issues in the repo can be solved by using V3.

Copy link
Contributor

@khuezy khuezy left a comment

Choose a reason for hiding this comment

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

LGTM. I've only look at the code in isolation and not as the whole application, so please excuse me if my comments are irrelevant from missing context.

Regarding:
experimentalBundledNextServer => we should deprecate this for 14.2+. We should also draw the line for which version we're supporting since it'll be a headache to support all the potential diff that Vercel will introduce in 14.3+

e2e tests => We should get an ion test app up before we officially introduce v3

git history => That's fine, squashing is also dangerous if a single line was missed.

cc: @fwang would be nice if you could deploy a test app and do a quick sanity check of the basic functionality.

},
experimentalBundledNextServer: true // This enables the bundled next server which is faster and reduce the size of the server
},
pageSsr: {
Copy link
Contributor

@khuezy khuezy Apr 11, 2024

Choose a reason for hiding this comment

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

Is this correct:
ssr => appDir
pageSsr => pagesDir

I'm wondering if people would easily understand/get this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily, you can give whatever name you want here, and you can mix app and page dir as much as you want. The ssr functions for example has a page/route3 route
You can also have as many different functions as you want

Copy link
Contributor

Choose a reason for hiding this comment

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

oops had a dyslexic typo, should have been is this correct, not this is correct... updated comment.

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 don't know how to properly explain these things, but i think with some time and people asking questions about it, we'll figure a proper way to explain it.

docs/pages/v3/config.mdx Show resolved Hide resolved
packages/open-next/src/build.ts Outdated Show resolved Hide resolved
//Page dir
computeCopyFilesForPage("pages/_app");
computeCopyFilesForPage("pages/_document");
computeCopyFilesForPage("pages/_error");
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to copy the 404 and 500 custom error pages? Or is that already included.
ref: https://nextjs.org/docs/pages/building-your-application/routing/custom-error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch,
Yes we do, for the created functions, we only copy the page in route.
We should probably add this inside a try catch as they are usually static or SSG and in those cases, we might not have a nft.json file

Copy link
Contributor

Choose a reason for hiding this comment

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

We can also make computeCopyFilesForPage async, then use await Promise.all([computeCopyFilesForPage...])
to run the fs operations in parallel to speed up the build time.

Might be worth considering if the time save is significant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah there is some room for improvement in terms of performance here. But computeCopyFilesForPage doesn't actually copy anything, it just compute every file that is necessary for a given server function.
The copying is done later and that's probably where it would help us.

At the moment it is fast enough i'd say (A lot more than the actual next build)

We could even improve the runtime performance if we do this properly.
https://github.com/sst/open-next/blob/dae9d98b0519c1ecb640b8c80d7fe0acca5b3886/packages/open-next/src/build/copyTracedFiles.ts#L189-L195

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 added the 404 and 500, they can be there if the user uses getStaticProps in them.

As for the performance improvement, i think we should see later if it becomes an issue. Making everything async may cause some other trouble as we may be copying thousands of files at the same time

if (hasAppDir) {
//App dir
try {
computeCopyFilesForPage("app/_not-found");
Copy link
Contributor

Choose a reason for hiding this comment

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

is the not-found convention prefixed with an underscore? I don't see a leading underscore in: https://nextjs.org/docs/app/api-reference/file-conventions/not-found

On the same note, do we need to handle error? https://nextjs.org/docs/app/api-reference/file-conventions/error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes same as the one above, we probably need to add it

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've checked and there is no separate error file generated as part of the bundle. Given that it's a client component, i think that it is bundled as one of the chunks and imported from some next built in component.

And the not-found component is always compiled as _not-found

packages/open-next/src/build/helper.ts Show resolved Hide resolved
packages/open-next/src/converters/aws-cloudfront.ts Outdated Show resolved Hide resolved
packages/open-next/src/core/routing/util.ts Outdated Show resolved Hide resolved
packages/open-next/src/plugins/edge.ts Outdated Show resolved Hide resolved
also fix an issue when both middleware and page try to set cookies
OpenNextNodeResponse also implements ServerResponse
@conico974
Copy link
Contributor Author

@khuezy I think i have to do a squash merge actually.
The main branch is protected against merge commits.
But it should be fine i've tested locally and there is no issue and we still get the history in the PR

@khuezy
Copy link
Contributor

khuezy commented May 3, 2024

That should be okay, nice work! SHIP IT :shipit:

@conico974
Copy link
Contributor Author

Ok let's go, let's hope i didn't mess the e2e tests

@conico974 conico974 merged commit b191ba3 into opennextjs:main May 3, 2024
3 checks passed
@conico974 conico974 deleted the feat/final-V3 branch October 29, 2024 10:40
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.

3 participants