Skip to content

Commit

Permalink
fix(vercel, netlify): always check nativeSWR future flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 27, 2023
1 parent 7976318 commit ccebe4e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
21 changes: 14 additions & 7 deletions src/presets/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export const netlify = defineNitroPreset({
},
hooks: {
"rollup:before": (nitro: Nitro) => {
if (!nitro.options.future.nativeSWR) {
deprecateSWR(nitro);
}
deprecateSWR(nitro);
},
async compiled(nitro: Nitro) {
await writeHeaders(nitro);
Expand All @@ -45,7 +43,9 @@ export const netlifyBuilder = defineNitroPreset({
extends: "netlify",
entry: "#internal/nitro/entries/netlify-builder",
hooks: {
"rollup:before": (nitro: Nitro) => deprecateSWR(nitro),
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
},
},
});

Expand All @@ -67,7 +67,9 @@ export const netlifyEdge = defineNitroPreset({
polyfill: ["#internal/nitro/polyfill/deno-env"],
},
hooks: {
"rollup:before": (nitro: Nitro) => deprecateSWR(nitro),
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
},
async compiled(nitro: Nitro) {
// https://docs.netlify.com/edge-functions/create-integration/
const manifest = {
Expand Down Expand Up @@ -100,7 +102,9 @@ export const netlifyStatic = defineNitroPreset({
preview: "npx serve ./static",
},
hooks: {
"rollup:before": (nitro: Nitro) => deprecateSWR(nitro),
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
},
async compiled(nitro: Nitro) {
await writeHeaders(nitro);
await writeRedirects(nitro);
Expand Down Expand Up @@ -203,6 +207,9 @@ async function writeHeaders(nitro: Nitro) {
}

function deprecateSWR(nitro: Nitro) {
if (nitro.options.future.nativeSWR) {
return;
}
let hasLegacyOptions = false;
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
if ("isr" in value) {
Expand All @@ -221,7 +228,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 future versions."
"[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. Set `future.nativeSWR: true` nitro config disable this warning."
);
}
}
17 changes: 11 additions & 6 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export const vercel = defineNitroPreset({
},
hooks: {
"rollup:before": (nitro: Nitro) => {
if (!nitro.options.future.nativeSWR) {
deprecateSWR(nitro);
}
deprecateSWR(nitro);
},
async compiled(nitro: Nitro) {
const buildConfigPath = resolve(nitro.options.output.dir, "config.json");
Expand Down Expand Up @@ -103,7 +101,9 @@ export const vercelEdge = defineNitroPreset({
},
},
hooks: {
"rollup:before": (nitro: Nitro) => deprecateSWR(nitro),
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
},
async compiled(nitro: Nitro) {
const buildConfigPath = resolve(nitro.options.output.dir, "config.json");
const buildConfig = generateBuildConfig(nitro);
Expand Down Expand Up @@ -136,7 +136,9 @@ export const vercelStatic = defineNitroPreset({
preview: "npx serve ./static",
},
hooks: {
"rollup:before": (nitro: Nitro) => deprecateSWR(nitro),
"rollup:before": (nitro: Nitro) => {
deprecateSWR(nitro);
},
async compiled(nitro: Nitro) {
const buildConfigPath = resolve(nitro.options.output.dir, "config.json");
const buildConfig = generateBuildConfig(nitro);
Expand Down Expand Up @@ -261,6 +263,9 @@ function generateEndpoint(url: string) {
}

function deprecateSWR(nitro: Nitro) {
if (nitro.options.future.nativeSWR) {
return;
}
let hasLegacyOptions = false;
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
if ("isr" in value) {
Expand All @@ -279,7 +284,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 future versions."
"[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. Set `future.nativeSWR: true` nitro config disable this warning."
);
}
}

0 comments on commit ccebe4e

Please sign in to comment.