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: future.nativeSWR #1212

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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."
pi0 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
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