Skip to content

Commit

Permalink
feat: future.nativeSWR (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored May 5, 2023
1 parent bd38969 commit 65665a4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions docs/content/3.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ Enable WASM support

When enabled, lagacy (unstable) experimental rollup externals algorithm will be used.

### `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
6 changes: 5 additions & 1 deletion 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
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 @@ -204,6 +204,9 @@ export interface NitroOptions extends PresetOptions {
legacyExternals?: boolean;
openAPI?: boolean;
};
future: {
nativeSWR: boolean;
};
serverAssets: ServerAssetDir[];
publicAssets: PublicAssetDir[];

Expand Down

0 comments on commit 65665a4

Please sign in to comment.