Skip to content

Commit

Permalink
feat: future.nativeSWR
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 5, 2023
1 parent f9c833c commit 18d9fe5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
10 changes: 10 additions & 0 deletions docs/content/3.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: `{}`
Expand Down
1 change: 1 addition & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const NitroDefaults: NitroConfig = {

// Features
experimental: {},
future: {},
storage: {},
devStorage: {},
bundledStorage: [],
Expand Down
8 changes: 6 additions & 2 deletions src/presets/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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."
);
}
}
8 changes: 6 additions & 2 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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."
);
}
}
3 changes: 3 additions & 0 deletions src/types/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ export interface NitroOptions extends PresetOptions {
wasm?: boolean | RollupWasmOptions;
legacyExternals?: boolean;
};
future: {
nativeSWR: boolean;
};
serverAssets: ServerAssetDir[];
publicAssets: PublicAssetDir[];

Expand Down

0 comments on commit 18d9fe5

Please sign in to comment.