From 18d9fe5d991f47618e35bf6e77e5c2797d13ccdf Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 5 May 2023 18:38:22 +0200 Subject: [PATCH] feat: `future.nativeSWR` --- docs/content/3.config.md | 10 ++++++++++ src/options.ts | 1 + src/presets/netlify.ts | 8 ++++++-- src/presets/vercel.ts | 8 ++++++-- src/types/nitro.ts | 3 +++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/content/3.config.md b/docs/content/3.config.md index 402883708e..e5fc99e4c2 100644 --- a/docs/content/3.config.md +++ b/docs/content/3.config.md @@ -58,6 +58,16 @@ Server runtime configuration. Enable experimental features. Currently, none are available! +### `future` + +- Default: `{}` + +New features pending for a major version to avoid breaking changes. + +#### `nativeSWR` + +Uses built-in SWR functionality (using caching layer and storage) for Netlify and Vercel presets instead of falling back to ISR behavior. + ### `storage` - Default: `{}` diff --git a/src/options.ts b/src/options.ts index 7278206977..46cf157e62 100644 --- a/src/options.ts +++ b/src/options.ts @@ -43,6 +43,7 @@ const NitroDefaults: NitroConfig = { // Features experimental: {}, + future: {}, storage: {}, devStorage: {}, bundledStorage: [], diff --git a/src/presets/netlify.ts b/src/presets/netlify.ts index 3d7ba35a94..75b9b84add 100644 --- a/src/presets/netlify.ts +++ b/src/presets/netlify.ts @@ -17,7 +17,11 @@ export const netlify = defineNitroPreset({ }, }, hooks: { - "rollup:before": (nitro: Nitro) => deprecateSWR(nitro), + "rollup:before": (nitro: Nitro) => { + if (!nitro.options.future.nativeSWR) { + deprecateSWR(nitro); + } + }, async compiled(nitro: Nitro) { await writeHeaders(nitro); await writeRedirects(nitro); @@ -210,7 +214,7 @@ function deprecateSWR(nitro: Nitro) { } if (hasLegacyOptions) { console.warn( - "[nitro] Nitro now uses `isr` option to configure ISR behavior on Netlify. Backwards-compatible support for `static` and `swr` support with Builder Functions will be removed in the next major release." + "[nitro] Nitro now uses `isr` option to configure ISR behavior on Netlify. Backwards-compatible support for `static` and `swr` support with Builder Functions will be removed in the future versions." ); } } diff --git a/src/presets/vercel.ts b/src/presets/vercel.ts index 1ff5e23de4..e40d1137f3 100644 --- a/src/presets/vercel.ts +++ b/src/presets/vercel.ts @@ -22,7 +22,11 @@ export const vercel = defineNitroPreset({ preview: "", }, hooks: { - "rollup:before": (nitro: Nitro) => deprecateSWR(nitro), + "rollup:before": (nitro: Nitro) => { + if (!nitro.options.future.nativeSWR) { + deprecateSWR(nitro); + } + }, async compiled(nitro: Nitro) { const buildConfigPath = resolve(nitro.options.output.dir, "config.json"); const buildConfig = generateBuildConfig(nitro); @@ -270,7 +274,7 @@ function deprecateSWR(nitro: Nitro) { } if (hasLegacyOptions) { console.warn( - "[nitro] Nitro now uses `isr` option to configure ISR behavior on Vercel. Backwards-compatible support for `static` and `swr` options within the Vercel Build Options API will be removed in the next major release." + "[nitro] Nitro now uses `isr` option to configure ISR behavior on Vercel. Backwards-compatible support for `static` and `swr` options within the Vercel Build Options API will be removed in the future versions." ); } } diff --git a/src/types/nitro.ts b/src/types/nitro.ts index 5b70b947eb..f0efa947e3 100644 --- a/src/types/nitro.ts +++ b/src/types/nitro.ts @@ -203,6 +203,9 @@ export interface NitroOptions extends PresetOptions { wasm?: boolean | RollupWasmOptions; legacyExternals?: boolean; }; + future: { + nativeSWR: boolean; + }; serverAssets: ServerAssetDir[]; publicAssets: PublicAssetDir[];