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

feat: use incremental cache during rendering #64

Merged

Conversation

james-elicx
Copy link
Contributor

@james-elicx james-elicx commented Oct 6, 2024

Changes:

  • Removes the NEXT_PRIVATE_MINIMAL_MODE env var.
  • Inlines the middleware manifest instead of it being dynamic require.
  • Removes the no fallback exception bubbling as this results in hanging promises when SSG routes disable fallback dynamic params.

We currently enable the private version of minimal mode, alongside the public version of minimal mode. This is problematic as it is intended to be used by cloud providers when they have an additional layer on top of the worker that handles routing systems, cdn caching, static routes, etc.. That's why Vercel uses it. As a result, we're disabling specific behaviour without building our own system that will handle that.

There's two ways to look at this;

  1. Enable the internal minimal mode -> build our own routing system, cdn caching logic, static routes/isr handling, etc.
  2. Disable the internal minimal mode -> let Next.js handle routing and provide a custom cache handler to the incremental cache, and things should work.

The option that is probably going to be easier to maintain and support in the long run is number 2 - disabling the internal minimal mode and just providing a custom cache handler that the incremental cache can use, which we are already partly doing.


Here's what happens in the base server when making a request to a route that is SSG/ISR.

  • Finds a match for the route.
  • Starts the logic for rendering a route module.
    • Calls the response cache with a callback that will SSR the page. (src)
    • Response cache calls the incremental cache. (src)
      • Incremental cache interfaces with the custom cache handler to find a cache entry for the key.
    • If cache entry should be used / is fresh
      • the response cache returns instead of calling the render callback. (src)
    • If cache entry is stale / cache miss
      • the response cache calls the render callback that it was given. (src)
      • it tries to put the response from SSR into the incremental cache.
      • if there was no response from the render callback due to 404 and there is no fallback function for it to invoke, it bubbled a NoFallbackException back to the worker.
  • Response returned to user.

The problem with using the private minimal mode for this is that the incremental cache is disabled in the response cache, blocking ssg/isr from functioning!

Copy link

pkg-pr-new bot commented Oct 6, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@opennextjs/cloudflare@64

commit: e8e0b0c

@james-elicx james-elicx force-pushed the james/disable-internal-minimal-mode branch 4 times, most recently from 56127f5 to 193aa27 Compare October 6, 2024 19:47
@james-elicx james-elicx force-pushed the james/disable-internal-minimal-mode branch from 193aa27 to 78946b2 Compare October 6, 2024 19:51
@james-elicx james-elicx marked this pull request as ready for review October 6, 2024 19:52
@james-elicx james-elicx force-pushed the james/disable-internal-minimal-mode branch 2 times, most recently from 4906890 to c8e492e Compare October 6, 2024 23:23
@james-elicx james-elicx force-pushed the james/disable-internal-minimal-mode branch from c8e492e to abdb2b8 Compare October 6, 2024 23:25
Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

The changes look great - could you please update the PR according to the comment?

Copy link

changeset-bot bot commented Oct 7, 2024

⚠️ No Changeset found

Latest commit: e8e0b0c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@james-elicx james-elicx requested a review from vicb October 7, 2024 07:33
Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for the updates!

Could you please update the name of the patches and this will be good to go

@james-elicx james-elicx requested a review from vicb October 7, 2024 08:04
Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

Thanks again 🎉

@vicb vicb merged commit ba9af72 into opennextjs:main Oct 7, 2024
7 checks passed
@james-elicx james-elicx deleted the james/disable-internal-minimal-mode branch October 7, 2024 08:25
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