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(netlify): experimental support v2 functions ISR via targeted cache-control headers #2406

Merged

Conversation

serhalp
Copy link
Contributor

@serhalp serhalp commented May 1, 2024

πŸ”— Linked issue

Supersedes #1823.
Closes #1842.
Closes #1938.

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Netlify introduced a new Functions interface last year. This updates Nitro to use this interface.

Previously, ISR in Nitro had been implemented on Netlify via its proprietary On-Demand Builders platform primitive, which only supports "v1" Functions. Now that there's momentum around Targeted HTTP Cache Control and that Netlify supports it, we can implement ISR in Nitro via these simple, standard HTTP headers instead.

By virtue of switching to the standard Netlify Functions interface, this also happens to:

  • allow streaming responses
  • add better support for "hybrid rendering", e.g. if you set prerender: true on a specific route, that will actually work as intended now
  • remove the imposed 60s delay after a background generation request before which the new response will be served for subsequent requests (this was an ODB limitation)
  • fix a bug where we were setting set-cookie: undefined on responses
  • remove usage of an undocumented functions-internal/server.json Netlify config file
  • ... which wasn't working when using netlify dev in local development anyway

This also configures a human-friendly name and some metadata on the function.

Note: I removed the netlify_builder preset, since there's no reason to use this anymore. I'm not even sure why it was ever exposed as a preset. I did this as a separate commit, so if you consider this a breaking change I can pull it out into a separate PR.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

src/presets/index.ts Outdated Show resolved Hide resolved
src/presets/netlify.ts Outdated Show resolved Hide resolved
src/runtime/entries/netlify.ts Outdated Show resolved Hide resolved
src/presets/netlify.ts Outdated Show resolved Hide resolved
@pi0 pi0 mentioned this pull request May 1, 2024
8 tasks
@pi0 pi0 changed the title feat(netlify): use "v2" Netlify Functions and re-implement ISR via targeted cache-control headers feat(netlify): use v3 functions and re-implement isr via targeted cache-control headers May 1, 2024
@pi0 pi0 changed the title feat(netlify): use v3 functions and re-implement isr via targeted cache-control headers feat(netlify): use v2 functions and re-implement isr via targeted cache-control headers May 1, 2024
Previously, ISR in Nitro had been implemented on Netlify via its proprietary [On-Demand
Builders](https://docs.netlify.com/configure-builds/on-demand-builders/) platform
primitive. Now that there's momentum around [Targeted HTTP Cache
Control](https://httpwg.org/specs/rfc9213.html) and that [Netlify supports
it](https://docs.netlify.com/platform/caching/#supported-cache-control-headers), we can
implement ISR in Nitro via these simple, standard HTTP headers instead.

By virtue of switching to the standard Netlify Functions interface, this also happens to:
- allow streaming responses
- add better support for "hybrid rendering", e.g. if you set `prerender: true`
  on a specific route, that will actually work as intended now
- remove the imposed 60s delay after a background generation request
  before which the new response will be served for subsequent requests
  (this was an ODB limitation)
- fix a bug where we were setting `set-cookie: undefined` on responses
- remove usage of an undocumented `functions-internal/server.json` Netlify config file
- ... which wasn't working when using `netlify dev` in local development anyway

This also configures a human-friendly name and some metadata on the function.

Supersedes nitrojs#1823.
Closes nitrojs#1842.
Closes nitrojs#1938.
@pi0 pi0 force-pushed the serhalp/fra-356-update-nitro-to-use-v2-functions branch from 2fc17ff to 2c106d9 Compare May 1, 2024 15:31
@pi0
Copy link
Member

pi0 commented May 1, 2024

(omitted 4541cf9 and 2fc17ff for now to reduce diff)

@Rigo-m
Copy link
Contributor

Rigo-m commented May 1, 2024

Super @serhalp 😍

@pi0 pi0 force-pushed the serhalp/fra-356-update-nitro-to-use-v2-functions branch from 1754331 to 5f02fea Compare May 1, 2024 16:01
@pi0 pi0 changed the title feat(netlify): use v2 functions and re-implement isr via targeted cache-control headers feat(netlify): support v2 functions (opt-in) and re-implement isr via targeted cache-control headers May 1, 2024
@pi0 pi0 changed the title feat(netlify): support v2 functions (opt-in) and re-implement isr via targeted cache-control headers feat(netlify): experimental support v2 functions ISR via targeted cache-control headers May 7, 2024
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks! Merging as is mainly to allow experimenting on main branch and do pre-release refactors.

The confusing v1/v2 scheme that I added to list commits will be removed likely before releasing next versions.

@pi0 pi0 merged commit 9fcaca6 into nitrojs:main May 7, 2024
4 checks passed
@pi0 pi0 mentioned this pull request Jun 13, 2024
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.

Netlify : undefined set-cookie Netlify new functions v2 format
3 participants