From 6af0727cc11aa58b8275686016a6e8a6fc43f203 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Tue, 15 Apr 2025 11:32:24 +0200 Subject: [PATCH 01/14] add experimental e2e app --- examples/experimental/.gitignore | 41 ++ examples/experimental/README.md | 3 + examples/experimental/next.config.ts | 15 + examples/experimental/open-next.config.ts | 14 + examples/experimental/package.json | 24 ++ examples/experimental/src/app/favicon.ico | Bin 0 -> 25931 bytes examples/experimental/src/app/globals.css | 42 ++ examples/experimental/src/app/layout.tsx | 32 ++ examples/experimental/src/app/page.module.css | 168 ++++++++ examples/experimental/src/app/page.tsx | 14 + examples/experimental/src/app/ppr/page.tsx | 16 + .../experimental/src/components/dynamic.tsx | 18 + .../experimental/src/components/static.tsx | 8 + examples/experimental/tsconfig.json | 27 ++ examples/sst/sst.config.ts | 7 +- examples/sst/stacks/Experimental.ts | 14 + pnpm-lock.yaml | 385 ++++++++++++++++++ 17 files changed, 827 insertions(+), 1 deletion(-) create mode 100644 examples/experimental/.gitignore create mode 100644 examples/experimental/README.md create mode 100644 examples/experimental/next.config.ts create mode 100644 examples/experimental/open-next.config.ts create mode 100644 examples/experimental/package.json create mode 100644 examples/experimental/src/app/favicon.ico create mode 100644 examples/experimental/src/app/globals.css create mode 100644 examples/experimental/src/app/layout.tsx create mode 100644 examples/experimental/src/app/page.module.css create mode 100644 examples/experimental/src/app/page.tsx create mode 100644 examples/experimental/src/app/ppr/page.tsx create mode 100644 examples/experimental/src/components/dynamic.tsx create mode 100644 examples/experimental/src/components/static.tsx create mode 100644 examples/experimental/tsconfig.json create mode 100644 examples/sst/stacks/Experimental.ts diff --git a/examples/experimental/.gitignore b/examples/experimental/.gitignore new file mode 100644 index 000000000..5ef6a5207 --- /dev/null +++ b/examples/experimental/.gitignore @@ -0,0 +1,41 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.* +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/versions + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# env files (can opt-in for committing if needed) +.env* + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts diff --git a/examples/experimental/README.md b/examples/experimental/README.md new file mode 100644 index 000000000..0009a0255 --- /dev/null +++ b/examples/experimental/README.md @@ -0,0 +1,3 @@ +# Experimental + +This project is meant to test experimental features that are only available on canary builds of Next.js. \ No newline at end of file diff --git a/examples/experimental/next.config.ts b/examples/experimental/next.config.ts new file mode 100644 index 000000000..a9f9d08c1 --- /dev/null +++ b/examples/experimental/next.config.ts @@ -0,0 +1,15 @@ +import type { NextConfig } from "next"; + +const nextConfig: NextConfig = { + /* config options here */ + cleanDistDir: true, + output: "standalone", + eslint: { + ignoreDuringBuilds: true, + }, + experimental: { + ppr: "incremental", + }, +}; + +export default nextConfig; diff --git a/examples/experimental/open-next.config.ts b/examples/experimental/open-next.config.ts new file mode 100644 index 000000000..5ff6edf53 --- /dev/null +++ b/examples/experimental/open-next.config.ts @@ -0,0 +1,14 @@ +const config = { + default: { + override: { + wrapper: "aws-lambda-streaming", + queue: "sqs-lite", + incrementalCache: "s3-lite", + tagCache: "dynamodb-lite", + }, + }, + functions: {}, + buildCommand: "npx turbo build", +}; + +export default config; diff --git a/examples/experimental/package.json b/examples/experimental/package.json new file mode 100644 index 000000000..62aed07a3 --- /dev/null +++ b/examples/experimental/package.json @@ -0,0 +1,24 @@ +{ + "name": "experimental", + "version": "0.1.0", + "private": true, + "scripts": { + "openbuild": "node ../../packages/open-next/dist/index.js build", + "dev": "next dev --turbopack", + "build": "next build", + "start": "next start", + "lint": "next lint", + "clean": "rm -rf .turbo node_modules .next .open-next" + }, + "dependencies": { + "next": "15.3.1-canary.8", + "react": "catalog:", + "react-dom": "catalog:" + }, + "devDependencies": { + "@types/node": "catalog:", + "@types/react": "catalog:", + "@types/react-dom": "catalog:", + "typescript": "catalog:" + } +} diff --git a/examples/experimental/src/app/favicon.ico b/examples/experimental/src/app/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..718d6fea4835ec2d246af9800eddb7ffb276240c GIT binary patch literal 25931 zcmeHv30#a{`}aL_*G&7qml|y<+KVaDM2m#dVr!KsA!#An?kSQM(q<_dDNCpjEux83 zLb9Z^XxbDl(w>%i@8hT6>)&Gu{h#Oeyszu?xtw#Zb1mO{pgX9699l+Qppw7jXaYf~-84xW z)w4x8?=youko|}Vr~(D$UXIbiXABHh`p1?nn8Po~fxRJv}|0e(BPs|G`(TT%kKVJAdg5*Z|x0leQq0 zkdUBvb#>9F()jo|T~kx@OM8$9wzs~t2l;K=woNssA3l6|sx2r3+kdfVW@e^8e*E}v zA1y5{bRi+3Z`uD3{F7LgFJDdvm;nJilkzDku>BwXH(8ItVCXk*-lSJnR?-2UN%hJ){&rlvg`CDTj z)Bzo!3v7Ou#83zEDEFcKt(f1E0~=rqeEbTnMvWR#{+9pg%7G8y>u1OVRUSoox-ovF z2Ydma(;=YuBY(eI|04{hXzZD6_f(v~H;C~y5=DhAC{MMS>2fm~1H_t2$56pc$NH8( z5bH|<)71dV-_oCHIrzrT`2s-5w_+2CM0$95I6X8p^r!gHp+j_gd;9O<1~CEQQGS8) zS9Qh3#p&JM-G8rHekNmKVewU;pJRcTAog68KYo^dRo}(M>36U4Us zfgYWSiHZL3;lpWT=zNAW>Dh#mB!_@Lg%$ms8N-;aPqMn+C2HqZgz&9~Eu z4|Kp<`$q)Uw1R?y(~S>ePdonHxpV1#eSP1B;Ogo+-Pk}6#0GsZZ5!||ev2MGdh}_m z{DeR7?0-1^zVs&`AV6Vt;r3`I`OI_wgs*w=eO%_#7Kepl{B@xiyCANc(l zzIyd4y|c6PXWq9-|KM8(zIk8LPk(>a)zyFWjhT!$HJ$qX1vo@d25W<fvZQ2zUz5WRc(UnFMKHwe1| zWmlB1qdbiA(C0jmnV<}GfbKtmc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br^V%>j!gS)D*q*f_-qf8&D;W1dJgQMlaH5er zN2U<%Smb7==vE}dDI8K7cKz!vs^73o9f>2sgiTzWcwY|BMYHH5%Vn7#kiw&eItCqa zIkR2~Q}>X=Ar8W|^Ms41Fm8o6IB2_j60eOeBB1Br!boW7JnoeX6Gs)?7rW0^5psc- zjS16yb>dFn>KPOF;imD}e!enuIniFzv}n$m2#gCCv4jM#ArwlzZ$7@9&XkFxZ4n!V zj3dyiwW4Ki2QG{@i>yuZXQizw_OkZI^-3otXC{!(lUpJF33gI60ak;Uqitp74|B6I zgg{b=Iz}WkhCGj1M=hu4#Aw173YxIVbISaoc z-nLZC*6Tgivd5V`K%GxhBsp@SUU60-rfc$=wb>zdJzXS&-5(NRRodFk;Kxk!S(O(a0e7oY=E( zAyS;Ow?6Q&XA+cnkCb{28_1N8H#?J!*$MmIwLq^*T_9-z^&UE@A(z9oGYtFy6EZef LrJugUA?W`A8`#=m literal 0 HcmV?d00001 diff --git a/examples/experimental/src/app/globals.css b/examples/experimental/src/app/globals.css new file mode 100644 index 000000000..e3734be15 --- /dev/null +++ b/examples/experimental/src/app/globals.css @@ -0,0 +1,42 @@ +:root { + --background: #ffffff; + --foreground: #171717; +} + +@media (prefers-color-scheme: dark) { + :root { + --background: #0a0a0a; + --foreground: #ededed; + } +} + +html, +body { + max-width: 100vw; + overflow-x: hidden; +} + +body { + color: var(--foreground); + background: var(--background); + font-family: Arial, Helvetica, sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +* { + box-sizing: border-box; + padding: 0; + margin: 0; +} + +a { + color: inherit; + text-decoration: none; +} + +@media (prefers-color-scheme: dark) { + html { + color-scheme: dark; + } +} diff --git a/examples/experimental/src/app/layout.tsx b/examples/experimental/src/app/layout.tsx new file mode 100644 index 000000000..42fc323e4 --- /dev/null +++ b/examples/experimental/src/app/layout.tsx @@ -0,0 +1,32 @@ +import type { Metadata } from "next"; +import { Geist, Geist_Mono } from "next/font/google"; +import "./globals.css"; + +const geistSans = Geist({ + variable: "--font-geist-sans", + subsets: ["latin"], +}); + +const geistMono = Geist_Mono({ + variable: "--font-geist-mono", + subsets: ["latin"], +}); + +export const metadata: Metadata = { + title: "Create Next App", + description: "Generated by create next app", +}; + +export default function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return ( + + + {children} + + + ); +} diff --git a/examples/experimental/src/app/page.module.css b/examples/experimental/src/app/page.module.css new file mode 100644 index 000000000..a11c8f317 --- /dev/null +++ b/examples/experimental/src/app/page.module.css @@ -0,0 +1,168 @@ +.page { + --gray-rgb: 0, 0, 0; + --gray-alpha-200: rgba(var(--gray-rgb), 0.08); + --gray-alpha-100: rgba(var(--gray-rgb), 0.05); + + --button-primary-hover: #383838; + --button-secondary-hover: #f2f2f2; + + display: grid; + grid-template-rows: 20px 1fr 20px; + align-items: center; + justify-items: center; + min-height: 100svh; + padding: 80px; + gap: 64px; + font-family: var(--font-geist-sans); +} + +@media (prefers-color-scheme: dark) { + .page { + --gray-rgb: 255, 255, 255; + --gray-alpha-200: rgba(var(--gray-rgb), 0.145); + --gray-alpha-100: rgba(var(--gray-rgb), 0.06); + + --button-primary-hover: #ccc; + --button-secondary-hover: #1a1a1a; + } +} + +.main { + display: flex; + flex-direction: column; + gap: 32px; + grid-row-start: 2; +} + +.main ol { + font-family: var(--font-geist-mono); + padding-left: 0; + margin: 0; + font-size: 14px; + line-height: 24px; + letter-spacing: -0.01em; + list-style-position: inside; +} + +.main li:not(:last-of-type) { + margin-bottom: 8px; +} + +.main code { + font-family: inherit; + background: var(--gray-alpha-100); + padding: 2px 4px; + border-radius: 4px; + font-weight: 600; +} + +.ctas { + display: flex; + gap: 16px; +} + +.ctas a { + appearance: none; + border-radius: 128px; + height: 48px; + padding: 0 20px; + border: none; + border: 1px solid transparent; + transition: + background 0.2s, + color 0.2s, + border-color 0.2s; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; + font-size: 16px; + line-height: 20px; + font-weight: 500; +} + +a.primary { + background: var(--foreground); + color: var(--background); + gap: 8px; +} + +a.secondary { + border-color: var(--gray-alpha-200); + min-width: 158px; +} + +.footer { + grid-row-start: 3; + display: flex; + gap: 24px; +} + +.footer a { + display: flex; + align-items: center; + gap: 8px; +} + +.footer img { + flex-shrink: 0; +} + +/* Enable hover only on non-touch devices */ +@media (hover: hover) and (pointer: fine) { + a.primary:hover { + background: var(--button-primary-hover); + border-color: transparent; + } + + a.secondary:hover { + background: var(--button-secondary-hover); + border-color: transparent; + } + + .footer a:hover { + text-decoration: underline; + text-underline-offset: 4px; + } +} + +@media (max-width: 600px) { + .page { + padding: 32px; + padding-bottom: 80px; + } + + .main { + align-items: center; + } + + .main ol { + text-align: center; + } + + .ctas { + flex-direction: column; + } + + .ctas a { + font-size: 14px; + height: 40px; + padding: 0 16px; + } + + a.secondary { + min-width: auto; + } + + .footer { + flex-wrap: wrap; + align-items: center; + justify-content: center; + } +} + +@media (prefers-color-scheme: dark) { + .logo { + filter: invert(); + } +} diff --git a/examples/experimental/src/app/page.tsx b/examples/experimental/src/app/page.tsx new file mode 100644 index 000000000..771b848ad --- /dev/null +++ b/examples/experimental/src/app/page.tsx @@ -0,0 +1,14 @@ +import styles from "./page.module.css"; +import Link from "next/link"; + +export default function Home() { + return ( +
+
+ +

Incremental PPR

+ +
+
+ ); +} diff --git a/examples/experimental/src/app/ppr/page.tsx b/examples/experimental/src/app/ppr/page.tsx new file mode 100644 index 000000000..11d017a76 --- /dev/null +++ b/examples/experimental/src/app/ppr/page.tsx @@ -0,0 +1,16 @@ +import { DynamicComponent } from "@/components/dynamic"; +import { StaticComponent } from "@/components/static"; +import { Suspense } from "react"; + +export const experimental_ppr = true; + +export default function PPRPage() { + return ( +
+ + Loading...
}> + + + + ); +} diff --git a/examples/experimental/src/components/dynamic.tsx b/examples/experimental/src/components/dynamic.tsx new file mode 100644 index 000000000..a57a493e8 --- /dev/null +++ b/examples/experimental/src/components/dynamic.tsx @@ -0,0 +1,18 @@ +import { headers } from "next/headers"; + +export async function DynamicComponent() { + const _headers = await headers(); + // Simulate a delay to mimic server-side calls + const date = await new Promise((resolve) => + setTimeout(() => { + resolve(new Date().toString()); + }, 1000), + ); + return ( +
+

Dynamic Component

+

This component should be SSR

+

{_headers.get("referer")}

+
+ ); +} diff --git a/examples/experimental/src/components/static.tsx b/examples/experimental/src/components/static.tsx new file mode 100644 index 000000000..8af73f9f0 --- /dev/null +++ b/examples/experimental/src/components/static.tsx @@ -0,0 +1,8 @@ +export function StaticComponent() { + return ( +
+

Static Component

+

This is a static component that does not change.

+
+ ); +} diff --git a/examples/experimental/tsconfig.json b/examples/experimental/tsconfig.json new file mode 100644 index 000000000..c1334095f --- /dev/null +++ b/examples/experimental/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "target": "ES2017", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "plugins": [ + { + "name": "next" + } + ], + "paths": { + "@/*": ["./src/*"] + } + }, + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/examples/sst/sst.config.ts b/examples/sst/sst.config.ts index 7d68f3f11..b215188bc 100644 --- a/examples/sst/sst.config.ts +++ b/examples/sst/sst.config.ts @@ -3,6 +3,7 @@ import type { SSTConfig } from "sst"; import { AppPagesRouter } from "./stacks/AppPagesRouter"; import { AppRouter } from "./stacks/AppRouter"; import { PagesRouter } from "./stacks/PagesRouter"; +import { Experimental } from "./stacks/Experimental"; export default { config(_input) { @@ -12,6 +13,10 @@ export default { }; }, stacks(app) { - app.stack(AppRouter).stack(PagesRouter).stack(AppPagesRouter); + app + .stack(AppRouter) + .stack(PagesRouter) + .stack(AppPagesRouter) + .stack(Experimental); }, } satisfies SSTConfig; diff --git a/examples/sst/stacks/Experimental.ts b/examples/sst/stacks/Experimental.ts new file mode 100644 index 000000000..d41603db2 --- /dev/null +++ b/examples/sst/stacks/Experimental.ts @@ -0,0 +1,14 @@ +import { OpenNextCdkReferenceImplementation } from "./OpenNextReferenceImplementation"; + +export function Experimental({ stack }) { + const site = new OpenNextCdkReferenceImplementation(stack, "experimental", { + path: "../experimental", + environment: { + OPEN_NEXT_FORCE_NON_EMPTY_RESPONSE: "true", + }, + }); + + stack.addOutputs({ + url: `https://${site.distribution.domainName}`, + }); +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4327bfa4f..7813c5597 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -137,6 +137,31 @@ importers: specifier: 'catalog:' version: 5.6.3 + examples/experimental: + dependencies: + next: + specifier: 15.3.1-canary.8 + version: 15.3.1-canary.8(@playwright/test@1.49.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + react: + specifier: 'catalog:' + version: 19.0.0 + react-dom: + specifier: 'catalog:' + version: 19.0.0(react@19.0.0) + devDependencies: + '@types/node': + specifier: 'catalog:' + version: 20.17.6 + '@types/react': + specifier: 'catalog:' + version: 19.0.0 + '@types/react-dom': + specifier: 'catalog:' + version: 19.0.0 + typescript: + specifier: 'catalog:' + version: 5.6.3 + examples/pages-router: dependencies: '@example/shared': @@ -1009,6 +1034,9 @@ packages: '@emnapi/runtime@1.3.1': resolution: {integrity: sha512-kEBmG8KyqtxJZv+ygbEim+KCGtIq1fC22Ms3S4ziXmYKm8uyoLX0MHONVKwp+9opg390VaKRNt4a7A9NwmpNhw==} + '@emnapi/runtime@1.4.1': + resolution: {integrity: sha512-LMshMVP0ZhACNjQNYXiU1iZJ6QCcv0lUdPDPugqGvCGXt5xtRVBPdtA0qU12pEXZzpWAhWlZYptfdAFq10DOVQ==} + '@envelop/core@3.0.6': resolution: {integrity: sha512-06t1xCPXq6QFN7W1JUEf68aCwYN0OUDNAIoJe7bAqhaoa2vn7NCcuX1VHkJ/OWpmElUgCsRO6RiBbIru1in0Ig==} @@ -1608,105 +1636,215 @@ packages: cpu: [arm64] os: [darwin] + '@img/sharp-darwin-arm64@0.34.1': + resolution: {integrity: sha512-pn44xgBtgpEbZsu+lWf2KNb6OAf70X68k+yk69Ic2Xz11zHR/w24/U49XT7AeRwJ0Px+mhALhU5LPci1Aymk7A==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [arm64] + os: [darwin] + '@img/sharp-darwin-x64@0.33.5': resolution: {integrity: sha512-fyHac4jIc1ANYGRDxtiqelIbdWkIuQaI84Mv45KvGRRxSAa7o7d1ZKAOBaYbnepLC1WqxfpimdeWfvqqSGwR2Q==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [darwin] + '@img/sharp-darwin-x64@0.34.1': + resolution: {integrity: sha512-VfuYgG2r8BpYiOUN+BfYeFo69nP/MIwAtSJ7/Zpxc5QF3KS22z8Pvg3FkrSFJBPNQ7mmcUcYQFBmEQp7eu1F8Q==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [x64] + os: [darwin] + '@img/sharp-libvips-darwin-arm64@1.0.4': resolution: {integrity: sha512-XblONe153h0O2zuFfTAbQYAX2JhYmDHeWikp1LM9Hul9gVPjFY427k6dFEcOL72O01QxQsWi761svJ/ev9xEDg==} cpu: [arm64] os: [darwin] + '@img/sharp-libvips-darwin-arm64@1.1.0': + resolution: {integrity: sha512-HZ/JUmPwrJSoM4DIQPv/BfNh9yrOA8tlBbqbLz4JZ5uew2+o22Ik+tHQJcih7QJuSa0zo5coHTfD5J8inqj9DA==} + cpu: [arm64] + os: [darwin] + '@img/sharp-libvips-darwin-x64@1.0.4': resolution: {integrity: sha512-xnGR8YuZYfJGmWPvmlunFaWJsb9T/AO2ykoP3Fz/0X5XV2aoYBPkX6xqCQvUTKKiLddarLaxpzNe+b1hjeWHAQ==} cpu: [x64] os: [darwin] + '@img/sharp-libvips-darwin-x64@1.1.0': + resolution: {integrity: sha512-Xzc2ToEmHN+hfvsl9wja0RlnXEgpKNmftriQp6XzY/RaSfwD9th+MSh0WQKzUreLKKINb3afirxW7A0fz2YWuQ==} + cpu: [x64] + os: [darwin] + '@img/sharp-libvips-linux-arm64@1.0.4': resolution: {integrity: sha512-9B+taZ8DlyyqzZQnoeIvDVR/2F4EbMepXMc/NdVbkzsJbzkUjhXv/70GQJ7tdLA4YJgNP25zukcxpX2/SueNrA==} cpu: [arm64] os: [linux] + '@img/sharp-libvips-linux-arm64@1.1.0': + resolution: {integrity: sha512-IVfGJa7gjChDET1dK9SekxFFdflarnUB8PwW8aGwEoF3oAsSDuNUTYS+SKDOyOJxQyDC1aPFMuRYLoDInyV9Ew==} + cpu: [arm64] + os: [linux] + '@img/sharp-libvips-linux-arm@1.0.5': resolution: {integrity: sha512-gvcC4ACAOPRNATg/ov8/MnbxFDJqf/pDePbBnuBDcjsI8PssmjoKMAz4LtLaVi+OnSb5FK/yIOamqDwGmXW32g==} cpu: [arm] os: [linux] + '@img/sharp-libvips-linux-arm@1.1.0': + resolution: {integrity: sha512-s8BAd0lwUIvYCJyRdFqvsj+BJIpDBSxs6ivrOPm/R7piTs5UIwY5OjXrP2bqXC9/moGsyRa37eYWYCOGVXxVrA==} + cpu: [arm] + os: [linux] + + '@img/sharp-libvips-linux-ppc64@1.1.0': + resolution: {integrity: sha512-tiXxFZFbhnkWE2LA8oQj7KYR+bWBkiV2nilRldT7bqoEZ4HiDOcePr9wVDAZPi/Id5fT1oY9iGnDq20cwUz8lQ==} + cpu: [ppc64] + os: [linux] + '@img/sharp-libvips-linux-s390x@1.0.4': resolution: {integrity: sha512-u7Wz6ntiSSgGSGcjZ55im6uvTrOxSIS8/dgoVMoiGE9I6JAfU50yH5BoDlYA1tcuGS7g/QNtetJnxA6QEsCVTA==} cpu: [s390x] os: [linux] + '@img/sharp-libvips-linux-s390x@1.1.0': + resolution: {integrity: sha512-xukSwvhguw7COyzvmjydRb3x/09+21HykyapcZchiCUkTThEQEOMtBj9UhkaBRLuBrgLFzQ2wbxdeCCJW/jgJA==} + cpu: [s390x] + os: [linux] + '@img/sharp-libvips-linux-x64@1.0.4': resolution: {integrity: sha512-MmWmQ3iPFZr0Iev+BAgVMb3ZyC4KeFc3jFxnNbEPas60e1cIfevbtuyf9nDGIzOaW9PdnDciJm+wFFaTlj5xYw==} cpu: [x64] os: [linux] + '@img/sharp-libvips-linux-x64@1.1.0': + resolution: {integrity: sha512-yRj2+reB8iMg9W5sULM3S74jVS7zqSzHG3Ol/twnAAkAhnGQnpjj6e4ayUz7V+FpKypwgs82xbRdYtchTTUB+Q==} + cpu: [x64] + os: [linux] + '@img/sharp-libvips-linuxmusl-arm64@1.0.4': resolution: {integrity: sha512-9Ti+BbTYDcsbp4wfYib8Ctm1ilkugkA/uscUn6UXK1ldpC1JjiXbLfFZtRlBhjPZ5o1NCLiDbg8fhUPKStHoTA==} cpu: [arm64] os: [linux] + '@img/sharp-libvips-linuxmusl-arm64@1.1.0': + resolution: {integrity: sha512-jYZdG+whg0MDK+q2COKbYidaqW/WTz0cc1E+tMAusiDygrM4ypmSCjOJPmFTvHHJ8j/6cAGyeDWZOsK06tP33w==} + cpu: [arm64] + os: [linux] + '@img/sharp-libvips-linuxmusl-x64@1.0.4': resolution: {integrity: sha512-viYN1KX9m+/hGkJtvYYp+CCLgnJXwiQB39damAO7WMdKWlIhmYTfHjwSbQeUK/20vY154mwezd9HflVFM1wVSw==} cpu: [x64] os: [linux] + '@img/sharp-libvips-linuxmusl-x64@1.1.0': + resolution: {integrity: sha512-wK7SBdwrAiycjXdkPnGCPLjYb9lD4l6Ze2gSdAGVZrEL05AOUJESWU2lhlC+Ffn5/G+VKuSm6zzbQSzFX/P65A==} + cpu: [x64] + os: [linux] + '@img/sharp-linux-arm64@0.33.5': resolution: {integrity: sha512-JMVv+AMRyGOHtO1RFBiJy/MBsgz0x4AWrT6QoEVVTyh1E39TrCUpTRI7mx9VksGX4awWASxqCYLCV4wBZHAYxA==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] + '@img/sharp-linux-arm64@0.34.1': + resolution: {integrity: sha512-kX2c+vbvaXC6vly1RDf/IWNXxrlxLNpBVWkdpRq5Ka7OOKj6nr66etKy2IENf6FtOgklkg9ZdGpEu9kwdlcwOQ==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [arm64] + os: [linux] + '@img/sharp-linux-arm@0.33.5': resolution: {integrity: sha512-JTS1eldqZbJxjvKaAkxhZmBqPRGmxgu+qFKSInv8moZ2AmT5Yib3EQ1c6gp493HvrvV8QgdOXdyaIBrhvFhBMQ==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm] os: [linux] + '@img/sharp-linux-arm@0.34.1': + resolution: {integrity: sha512-anKiszvACti2sGy9CirTlNyk7BjjZPiML1jt2ZkTdcvpLU1YH6CXwRAZCA2UmRXnhiIftXQ7+Oh62Ji25W72jA==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [arm] + os: [linux] + '@img/sharp-linux-s390x@0.33.5': resolution: {integrity: sha512-y/5PCd+mP4CA/sPDKl2961b+C9d+vPAveS33s6Z3zfASk2j5upL6fXVPZi7ztePZ5CuH+1kW8JtvxgbuXHRa4Q==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [s390x] os: [linux] + '@img/sharp-linux-s390x@0.34.1': + resolution: {integrity: sha512-7s0KX2tI9mZI2buRipKIw2X1ufdTeaRgwmRabt5bi9chYfhur+/C1OXg3TKg/eag1W+6CCWLVmSauV1owmRPxA==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [s390x] + os: [linux] + '@img/sharp-linux-x64@0.33.5': resolution: {integrity: sha512-opC+Ok5pRNAzuvq1AG0ar+1owsu842/Ab+4qvU879ippJBHvyY5n2mxF1izXqkPYlGuP/M556uh53jRLJmzTWA==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] + '@img/sharp-linux-x64@0.34.1': + resolution: {integrity: sha512-wExv7SH9nmoBW3Wr2gvQopX1k8q2g5V5Iag8Zk6AVENsjwd+3adjwxtp3Dcu2QhOXr8W9NusBU6XcQUohBZ5MA==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [x64] + os: [linux] + '@img/sharp-linuxmusl-arm64@0.33.5': resolution: {integrity: sha512-XrHMZwGQGvJg2V/oRSUfSAfjfPxO+4DkiRh6p2AFjLQztWUuY/o8Mq0eMQVIY7HJ1CDQUJlxGGZRw1a5bqmd1g==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] + '@img/sharp-linuxmusl-arm64@0.34.1': + resolution: {integrity: sha512-DfvyxzHxw4WGdPiTF0SOHnm11Xv4aQexvqhRDAoD00MzHekAj9a/jADXeXYCDFH/DzYruwHbXU7uz+H+nWmSOQ==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [arm64] + os: [linux] + '@img/sharp-linuxmusl-x64@0.33.5': resolution: {integrity: sha512-WT+d/cgqKkkKySYmqoZ8y3pxx7lx9vVejxW/W4DOFMYVSkErR+w7mf2u8m/y4+xHe7yY9DAXQMWQhpnMuFfScw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] + '@img/sharp-linuxmusl-x64@0.34.1': + resolution: {integrity: sha512-pax/kTR407vNb9qaSIiWVnQplPcGU8LRIJpDT5o8PdAx5aAA7AS3X9PS8Isw1/WfqgQorPotjrZL3Pqh6C5EBg==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [x64] + os: [linux] + '@img/sharp-wasm32@0.33.5': resolution: {integrity: sha512-ykUW4LVGaMcU9lu9thv85CbRMAwfeadCJHRsg2GmeRa/cJxsVY9Rbd57JcMxBkKHag5U/x7TSBpScF4U8ElVzg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [wasm32] + '@img/sharp-wasm32@0.34.1': + resolution: {integrity: sha512-YDybQnYrLQfEpzGOQe7OKcyLUCML4YOXl428gOOzBgN6Gw0rv8dpsJ7PqTHxBnXnwXr8S1mYFSLSa727tpz0xg==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [wasm32] + '@img/sharp-win32-ia32@0.33.5': resolution: {integrity: sha512-T36PblLaTwuVJ/zw/LaH0PdZkRz5rd3SmMHX8GSmR7vtNSP5Z6bQkExdSK7xGWyxLw4sUknBuugTelgw2faBbQ==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [ia32] os: [win32] + '@img/sharp-win32-ia32@0.34.1': + resolution: {integrity: sha512-WKf/NAZITnonBf3U1LfdjoMgNO5JYRSlhovhRhMxXVdvWYveM4kM3L8m35onYIdh75cOMCo1BexgVQcCDzyoWw==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [ia32] + os: [win32] + '@img/sharp-win32-x64@0.33.5': resolution: {integrity: sha512-MpY/o8/8kj+EcnxwvrP4aTJSWw/aZ7JIGR4aBeZkZw5B7/Jn+tY9/VNwtcoGmdT7GfggGIU4kygOMSbYnOrAbg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [win32] + '@img/sharp-win32-x64@0.34.1': + resolution: {integrity: sha512-hw1iIAHpNE8q3uMIRCgGOeDoz9KtFNarFLQclLxr/LK1VBkj8nby18RjFvr6aP7USRYAjTZW6yisnBWMX571Tw==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + cpu: [x64] + os: [win32] + '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -1768,54 +1906,105 @@ packages: '@next/env@15.2.0': resolution: {integrity: sha512-eMgJu1RBXxxqqnuRJQh5RozhskoNUDHBFybvi+Z+yK9qzKeG7dadhv/Vp1YooSZmCnegf7JxWuapV77necLZNA==} + '@next/env@15.3.1-canary.8': + resolution: {integrity: sha512-ShZTo0hNhbTRrp7k6oUDSck4Xx4hhfSeLBp35jvGaw1QMZzWYr5v/oc0kEt0bfMdl+833flwKV7kFR3BnrULfg==} + '@next/swc-darwin-arm64@15.2.0': resolution: {integrity: sha512-rlp22GZwNJjFCyL7h5wz9vtpBVuCt3ZYjFWpEPBGzG712/uL1bbSkS675rVAUCRZ4hjoTJ26Q7IKhr5DfJrHDA==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] + '@next/swc-darwin-arm64@15.3.1-canary.8': + resolution: {integrity: sha512-ZaDynM+pbrnLLlBAxH/CDGp9KN79OFrLcT1ejlWyo86V3SS9Gyqr4nmTuvTevByTTpr1VHReQel8Zbq0Pttu7Q==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + '@next/swc-darwin-x64@15.2.0': resolution: {integrity: sha512-DiU85EqSHogCz80+sgsx90/ecygfCSGl5P3b4XDRVZpgujBm5lp4ts7YaHru7eVTyZMjHInzKr+w0/7+qDrvMA==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] + '@next/swc-darwin-x64@15.3.1-canary.8': + resolution: {integrity: sha512-BsMR8WqeCDAX8C9RYAO8TI4ttpuqKk2oYMb1+bCrOYi857SMfB4vWD4PWmMvj7mwFXGqrxly4W6CBQlD66A+fg==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + '@next/swc-linux-arm64-gnu@15.2.0': resolution: {integrity: sha512-VnpoMaGukiNWVxeqKHwi8MN47yKGyki5q+7ql/7p/3ifuU2341i/gDwGK1rivk0pVYbdv5D8z63uu9yMw0QhpQ==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] + '@next/swc-linux-arm64-gnu@15.3.1-canary.8': + resolution: {integrity: sha512-xL+K2SW+/46j/KnKNf1gizM1bxwcEaE56eCEG9RPoYS/lfxHLuHcR9O2MlcPI90g/rIN2HXmHeuKRbXbnVy15g==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + '@next/swc-linux-arm64-musl@15.2.0': resolution: {integrity: sha512-ka97/ssYE5nPH4Qs+8bd8RlYeNeUVBhcnsNUmFM6VWEob4jfN9FTr0NBhXVi1XEJpj3cMfgSRW+LdE3SUZbPrw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] + '@next/swc-linux-arm64-musl@15.3.1-canary.8': + resolution: {integrity: sha512-bzXlCUXkjIRsMTb6rr7OsWEQmdO2rZgKijnMGBJzEpa9ROq95VJTF+rdyrLmHuc4fPsAGDn/C18V3E1YOi4ipQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + '@next/swc-linux-x64-gnu@15.2.0': resolution: {integrity: sha512-zY1JduE4B3q0k2ZCE+DAF/1efjTXUsKP+VXRtrt/rJCTgDlUyyryx7aOgYXNc1d8gobys/Lof9P9ze8IyRDn7Q==} engines: {node: '>= 10'} cpu: [x64] os: [linux] + '@next/swc-linux-x64-gnu@15.3.1-canary.8': + resolution: {integrity: sha512-snbPQ9th7eoYYMZpNGhEvX4EbqGjjkiXzTEm2F/oDadlZR2wI6egtfQHiZqeczL7XwG3M66hBJ1/U20wdTDtvA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + '@next/swc-linux-x64-musl@15.2.0': resolution: {integrity: sha512-QqvLZpurBD46RhaVaVBepkVQzh8xtlUN00RlG4Iq1sBheNugamUNPuZEH1r9X1YGQo1KqAe1iiShF0acva3jHQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] + '@next/swc-linux-x64-musl@15.3.1-canary.8': + resolution: {integrity: sha512-5hmcaGazc3w6rg/gbQOrmuw0kKShf4Egs0JlUPop/ZiRDfZO5KlyrGY0hUD+2pLG7Yx3B/fTbj86cHKfQZDMBw==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + '@next/swc-win32-arm64-msvc@15.2.0': resolution: {integrity: sha512-ODZ0r9WMyylTHAN6pLtvUtQlGXBL9voljv6ujSlcsjOxhtXPI1Ag6AhZK0SE8hEpR1374WZZ5w33ChpJd5fsjw==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] + '@next/swc-win32-arm64-msvc@15.3.1-canary.8': + resolution: {integrity: sha512-t6uwWC/UbQ8CQGyBVbEmpcJC41yAvz2eZZGec9EoO0ZyQ/fbvjOkqfPnf+WcjWifWNeuiWogjN1UBg7YK9IaVA==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + '@next/swc-win32-x64-msvc@15.2.0': resolution: {integrity: sha512-8+4Z3Z7xa13NdUuUAcpVNA6o76lNPniBd9Xbo02bwXQXnZgFvEopwY2at5+z7yHl47X9qbZpvwatZ2BRo3EdZw==} engines: {node: '>= 10'} cpu: [x64] os: [win32] + '@next/swc-win32-x64-msvc@15.3.1-canary.8': + resolution: {integrity: sha512-93gNqVYwlr9bz6Pm5dQnqjpuOEQyvDre0+H39UqS7h2KuFh3sf2MejhAEr2uFEux4mb7TN0PlohaihO7YxJ3fw==} + engines: {node: '>= 10'} + cpu: [x64] + os: [win32] + '@node-minify/core@8.0.6': resolution: {integrity: sha512-/vxN46ieWDLU67CmgbArEvOb41zlYFOkOtr9QW9CnTrBLuTyGgkyNWC2y5+khvRw3Br58p2B5ZVSx/PxCTru6g==} engines: {node: '>=16.0.0'} @@ -4254,6 +4443,27 @@ packages: sass: optional: true + next@15.3.1-canary.8: + resolution: {integrity: sha512-Of5a3BTTIl/iUvL2a9Jh7m7G/H8z4Pj5Vs54CLvcdadokxSNgLOpjzbDgFR8J4PawLx6+MOMy19m9Cvr6EPGug==} + engines: {node: ^18.18.0 || ^19.8.0 || >= 20.0.0} + hasBin: true + peerDependencies: + '@opentelemetry/api': ^1.1.0 + '@playwright/test': ^1.41.2 + babel-plugin-react-compiler: '*' + react: ^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0 + react-dom: ^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0 + sass: ^1.3.0 + peerDependenciesMeta: + '@opentelemetry/api': + optional: true + '@playwright/test': + optional: true + babel-plugin-react-compiler: + optional: true + sass: + optional: true + node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} @@ -4771,6 +4981,11 @@ packages: engines: {node: '>=10'} hasBin: true + semver@7.7.1: + resolution: {integrity: sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==} + engines: {node: '>=10'} + hasBin: true + send@0.19.0: resolution: {integrity: sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==} engines: {node: '>= 0.8.0'} @@ -4798,6 +5013,10 @@ packages: resolution: {integrity: sha512-haPVm1EkS9pgvHrQ/F3Xy+hgcuMV0Wm9vfIBSiwZ05k+xgb0PkBQpGsAA/oWdDobNaZTH5ppvHtzCFbnSEwHVw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + sharp@0.34.1: + resolution: {integrity: sha512-1j0w61+eVxu7DawFJtnfYcvSv6qPFvfTaqzTQ2BLknVhHTwGS8sc63ZBF4rzkWMBVKybo4S5OBtDdZahh2A1xg==} + engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + shebang-command@1.2.0: resolution: {integrity: sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==} engines: {node: '>=0.10.0'} @@ -7502,6 +7721,11 @@ snapshots: tslib: 2.8.0 optional: true + '@emnapi/runtime@1.4.1': + dependencies: + tslib: 2.8.0 + optional: true + '@envelop/core@3.0.6': dependencies: '@envelop/types': 3.0.2 @@ -7862,76 +8086,154 @@ snapshots: '@img/sharp-libvips-darwin-arm64': 1.0.4 optional: true + '@img/sharp-darwin-arm64@0.34.1': + optionalDependencies: + '@img/sharp-libvips-darwin-arm64': 1.1.0 + optional: true + '@img/sharp-darwin-x64@0.33.5': optionalDependencies: '@img/sharp-libvips-darwin-x64': 1.0.4 optional: true + '@img/sharp-darwin-x64@0.34.1': + optionalDependencies: + '@img/sharp-libvips-darwin-x64': 1.1.0 + optional: true + '@img/sharp-libvips-darwin-arm64@1.0.4': optional: true + '@img/sharp-libvips-darwin-arm64@1.1.0': + optional: true + '@img/sharp-libvips-darwin-x64@1.0.4': optional: true + '@img/sharp-libvips-darwin-x64@1.1.0': + optional: true + '@img/sharp-libvips-linux-arm64@1.0.4': optional: true + '@img/sharp-libvips-linux-arm64@1.1.0': + optional: true + '@img/sharp-libvips-linux-arm@1.0.5': optional: true + '@img/sharp-libvips-linux-arm@1.1.0': + optional: true + + '@img/sharp-libvips-linux-ppc64@1.1.0': + optional: true + '@img/sharp-libvips-linux-s390x@1.0.4': optional: true + '@img/sharp-libvips-linux-s390x@1.1.0': + optional: true + '@img/sharp-libvips-linux-x64@1.0.4': optional: true + '@img/sharp-libvips-linux-x64@1.1.0': + optional: true + '@img/sharp-libvips-linuxmusl-arm64@1.0.4': optional: true + '@img/sharp-libvips-linuxmusl-arm64@1.1.0': + optional: true + '@img/sharp-libvips-linuxmusl-x64@1.0.4': optional: true + '@img/sharp-libvips-linuxmusl-x64@1.1.0': + optional: true + '@img/sharp-linux-arm64@0.33.5': optionalDependencies: '@img/sharp-libvips-linux-arm64': 1.0.4 optional: true + '@img/sharp-linux-arm64@0.34.1': + optionalDependencies: + '@img/sharp-libvips-linux-arm64': 1.1.0 + optional: true + '@img/sharp-linux-arm@0.33.5': optionalDependencies: '@img/sharp-libvips-linux-arm': 1.0.5 optional: true + '@img/sharp-linux-arm@0.34.1': + optionalDependencies: + '@img/sharp-libvips-linux-arm': 1.1.0 + optional: true + '@img/sharp-linux-s390x@0.33.5': optionalDependencies: '@img/sharp-libvips-linux-s390x': 1.0.4 optional: true + '@img/sharp-linux-s390x@0.34.1': + optionalDependencies: + '@img/sharp-libvips-linux-s390x': 1.1.0 + optional: true + '@img/sharp-linux-x64@0.33.5': optionalDependencies: '@img/sharp-libvips-linux-x64': 1.0.4 optional: true + '@img/sharp-linux-x64@0.34.1': + optionalDependencies: + '@img/sharp-libvips-linux-x64': 1.1.0 + optional: true + '@img/sharp-linuxmusl-arm64@0.33.5': optionalDependencies: '@img/sharp-libvips-linuxmusl-arm64': 1.0.4 optional: true + '@img/sharp-linuxmusl-arm64@0.34.1': + optionalDependencies: + '@img/sharp-libvips-linuxmusl-arm64': 1.1.0 + optional: true + '@img/sharp-linuxmusl-x64@0.33.5': optionalDependencies: '@img/sharp-libvips-linuxmusl-x64': 1.0.4 optional: true + '@img/sharp-linuxmusl-x64@0.34.1': + optionalDependencies: + '@img/sharp-libvips-linuxmusl-x64': 1.1.0 + optional: true + '@img/sharp-wasm32@0.33.5': dependencies: '@emnapi/runtime': 1.3.1 optional: true + '@img/sharp-wasm32@0.34.1': + dependencies: + '@emnapi/runtime': 1.4.1 + optional: true + '@img/sharp-win32-ia32@0.33.5': optional: true + '@img/sharp-win32-ia32@0.34.1': + optional: true + '@img/sharp-win32-x64@0.33.5': optional: true + '@img/sharp-win32-x64@0.34.1': + optional: true + '@isaacs/cliui@8.0.2': dependencies: string-width: 5.1.2 @@ -8014,30 +8316,56 @@ snapshots: '@next/env@15.2.0': {} + '@next/env@15.3.1-canary.8': {} + '@next/swc-darwin-arm64@15.2.0': optional: true + '@next/swc-darwin-arm64@15.3.1-canary.8': + optional: true + '@next/swc-darwin-x64@15.2.0': optional: true + '@next/swc-darwin-x64@15.3.1-canary.8': + optional: true + '@next/swc-linux-arm64-gnu@15.2.0': optional: true + '@next/swc-linux-arm64-gnu@15.3.1-canary.8': + optional: true + '@next/swc-linux-arm64-musl@15.2.0': optional: true + '@next/swc-linux-arm64-musl@15.3.1-canary.8': + optional: true + '@next/swc-linux-x64-gnu@15.2.0': optional: true + '@next/swc-linux-x64-gnu@15.3.1-canary.8': + optional: true + '@next/swc-linux-x64-musl@15.2.0': optional: true + '@next/swc-linux-x64-musl@15.3.1-canary.8': + optional: true + '@next/swc-win32-arm64-msvc@15.2.0': optional: true + '@next/swc-win32-arm64-msvc@15.3.1-canary.8': + optional: true + '@next/swc-win32-x64-msvc@15.2.0': optional: true + '@next/swc-win32-x64-msvc@15.3.1-canary.8': + optional: true + '@node-minify/core@8.0.6': dependencies: '@node-minify/utils': 8.0.6 @@ -10954,6 +11282,32 @@ snapshots: - '@babel/core' - babel-plugin-macros + next@15.3.1-canary.8(@playwright/test@1.49.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0): + dependencies: + '@next/env': 15.3.1-canary.8 + '@swc/counter': 0.1.3 + '@swc/helpers': 0.5.15 + busboy: 1.6.0 + caniuse-lite: 1.0.30001669 + postcss: 8.4.31 + react: 19.0.0 + react-dom: 19.0.0(react@19.0.0) + styled-jsx: 5.1.6(react@19.0.0) + optionalDependencies: + '@next/swc-darwin-arm64': 15.3.1-canary.8 + '@next/swc-darwin-x64': 15.3.1-canary.8 + '@next/swc-linux-arm64-gnu': 15.3.1-canary.8 + '@next/swc-linux-arm64-musl': 15.3.1-canary.8 + '@next/swc-linux-x64-gnu': 15.3.1-canary.8 + '@next/swc-linux-x64-musl': 15.3.1-canary.8 + '@next/swc-win32-arm64-msvc': 15.3.1-canary.8 + '@next/swc-win32-x64-msvc': 15.3.1-canary.8 + '@playwright/test': 1.49.1 + sharp: 0.34.1 + transitivePeerDependencies: + - '@babel/core' + - babel-plugin-macros + node-fetch@2.7.0: dependencies: whatwg-url: 5.0.0 @@ -11444,6 +11798,9 @@ snapshots: semver@7.6.3: {} + semver@7.7.1: + optional: true + send@0.19.0: dependencies: debug: 2.6.9 @@ -11535,6 +11892,34 @@ snapshots: '@img/sharp-win32-x64': 0.33.5 optional: true + sharp@0.34.1: + dependencies: + color: 4.2.3 + detect-libc: 2.0.3 + semver: 7.7.1 + optionalDependencies: + '@img/sharp-darwin-arm64': 0.34.1 + '@img/sharp-darwin-x64': 0.34.1 + '@img/sharp-libvips-darwin-arm64': 1.1.0 + '@img/sharp-libvips-darwin-x64': 1.1.0 + '@img/sharp-libvips-linux-arm': 1.1.0 + '@img/sharp-libvips-linux-arm64': 1.1.0 + '@img/sharp-libvips-linux-ppc64': 1.1.0 + '@img/sharp-libvips-linux-s390x': 1.1.0 + '@img/sharp-libvips-linux-x64': 1.1.0 + '@img/sharp-libvips-linuxmusl-arm64': 1.1.0 + '@img/sharp-libvips-linuxmusl-x64': 1.1.0 + '@img/sharp-linux-arm': 0.34.1 + '@img/sharp-linux-arm64': 0.34.1 + '@img/sharp-linux-s390x': 0.34.1 + '@img/sharp-linux-x64': 0.34.1 + '@img/sharp-linuxmusl-arm64': 0.34.1 + '@img/sharp-linuxmusl-x64': 0.34.1 + '@img/sharp-wasm32': 0.34.1 + '@img/sharp-win32-ia32': 0.34.1 + '@img/sharp-win32-x64': 0.34.1 + optional: true + shebang-command@1.2.0: dependencies: shebang-regex: 1.0.0 From 77a41ecf69ff36ecaa78354e6f2571afadea8956 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Wed, 16 Apr 2025 11:12:14 +0200 Subject: [PATCH 02/14] add e2e test --- .github/workflows/e2e.yml | 3 +++ examples/experimental/package.json | 4 ++-- packages/tests-e2e/playwright.config.js | 7 ++++++ .../tests-e2e/tests/experimental/ppr.test.ts | 22 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 packages/tests-e2e/tests/experimental/ppr.test.ts diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index af953ae09..d903a6025 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -111,6 +111,7 @@ jobs: - name: Install Nextjs in app-pages-router working-directory: examples/app-pages-router run: pnpm add next@${{ needs.check_next_version.outputs.previousNextVersion }} + # We do not install the latest canary of Next in the experimental app. - name: Get Playwright version id: playwright-version @@ -157,6 +158,8 @@ jobs: echo "PAGES_ROUTER_URL=$PAGES_ROUTER_URL" >> $GITHUB_ENV APP_PAGES_ROUTER_URL=$(jq -r '.["e2e-example-AppPagesRouter"].url' .sst/outputs.json) echo "APP_PAGES_ROUTER_URL=$APP_PAGES_ROUTER_URL" >> $GITHUB_ENV + EXPERIMENTAL_APP_URL=$(jq -r '.["e2e-example-Experimental"].url' .sst/outputs.json) + echo "EXPERIMENTAL_APP_URL=$EXPERIMENTAL_APP_URL" >> $GITHUB_ENV - name: Run e2e Test run: npm run e2e:test diff --git a/examples/experimental/package.json b/examples/experimental/package.json index 62aed07a3..f47bcbc63 100644 --- a/examples/experimental/package.json +++ b/examples/experimental/package.json @@ -4,9 +4,9 @@ "private": true, "scripts": { "openbuild": "node ../../packages/open-next/dist/index.js build", - "dev": "next dev --turbopack", + "dev": "next dev --turbopack --port 3004", "build": "next build", - "start": "next start", + "start": "next start --port 3004", "lint": "next lint", "clean": "rm -rf .turbo node_modules .next .open-next" }, diff --git a/packages/tests-e2e/playwright.config.js b/packages/tests-e2e/playwright.config.js index fe7e08be2..097102242 100644 --- a/packages/tests-e2e/playwright.config.js +++ b/packages/tests-e2e/playwright.config.js @@ -23,5 +23,12 @@ export default defineConfig({ baseURL: process.env.APP_PAGES_ROUTER_URL || "http://localhost:3003", }, }, + { + name: "experimental", + testMatch: ["tests/experimental/*.test.ts"], + use: { + baseURL: process.env.EXPERIMENTAL_APP_URL || "http://localhost:3004", + }, + }, ], }); diff --git a/packages/tests-e2e/tests/experimental/ppr.test.ts b/packages/tests-e2e/tests/experimental/ppr.test.ts new file mode 100644 index 000000000..896571186 --- /dev/null +++ b/packages/tests-e2e/tests/experimental/ppr.test.ts @@ -0,0 +1,22 @@ +import { expect, test } from "@playwright/test"; + +test("PPR should show loading first", async ({ page }) => { + await page.goto("/"); + await page.getByRole("link", { name: "Incremental PPR" }).click(); + await page.waitForURL("/ppr"); + const loading = page.getByText("Loading..."); + await expect(loading).toBeVisible(); + const el = page.getByText("Dynamic Component"); + await expect(el).toBeVisible(); +}); + +test("PPR rsc prefetch request should be cached", async ({ request }) => { + const resp = await request.get("/ppr", { + headers: { rsc: "1", "next-router-prefetch": "1" }, + }); + expect(resp.status()).toEqual(200); + const headers = resp.headers(); + expect(headers["x-nextjs-postponed"]).toEqual("1"); + expect(headers["x-nextjs-cache"]).toEqual("HIT"); + expect(headers["cache-control"]).toEqual("s-maxage=31536000"); +}); From 4dce529542291dc32e94994452d7382db0e4aeae Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Wed, 16 Apr 2025 11:17:17 +0200 Subject: [PATCH 03/14] lint --- examples/experimental/src/app/page.module.css | 5 +---- examples/experimental/src/app/page.tsx | 2 +- examples/sst/sst.config.ts | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/experimental/src/app/page.module.css b/examples/experimental/src/app/page.module.css index a11c8f317..5c7b57e9e 100644 --- a/examples/experimental/src/app/page.module.css +++ b/examples/experimental/src/app/page.module.css @@ -68,10 +68,7 @@ padding: 0 20px; border: none; border: 1px solid transparent; - transition: - background 0.2s, - color 0.2s, - border-color 0.2s; + transition: background 0.2s, color 0.2s, border-color 0.2s; cursor: pointer; display: flex; align-items: center; diff --git a/examples/experimental/src/app/page.tsx b/examples/experimental/src/app/page.tsx index 771b848ad..f14e5dad0 100644 --- a/examples/experimental/src/app/page.tsx +++ b/examples/experimental/src/app/page.tsx @@ -1,5 +1,5 @@ -import styles from "./page.module.css"; import Link from "next/link"; +import styles from "./page.module.css"; export default function Home() { return ( diff --git a/examples/sst/sst.config.ts b/examples/sst/sst.config.ts index b215188bc..32881d67c 100644 --- a/examples/sst/sst.config.ts +++ b/examples/sst/sst.config.ts @@ -2,8 +2,8 @@ import type { SSTConfig } from "sst"; import { AppPagesRouter } from "./stacks/AppPagesRouter"; import { AppRouter } from "./stacks/AppRouter"; -import { PagesRouter } from "./stacks/PagesRouter"; import { Experimental } from "./stacks/Experimental"; +import { PagesRouter } from "./stacks/PagesRouter"; export default { config(_input) { From 4b8da9914ffd03a9ba31ef7acc27357a1df7aacb Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Fri, 18 Apr 2025 13:31:24 +0200 Subject: [PATCH 04/14] add node middleware --- examples/experimental/next.config.ts | 1 + examples/experimental/src/middleware.ts | 27 +++++++++++++++++ .../tests/experimental/nodeMiddleware.test.ts | 29 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 examples/experimental/src/middleware.ts create mode 100644 packages/tests-e2e/tests/experimental/nodeMiddleware.test.ts diff --git a/examples/experimental/next.config.ts b/examples/experimental/next.config.ts index a9f9d08c1..c3fcdb402 100644 --- a/examples/experimental/next.config.ts +++ b/examples/experimental/next.config.ts @@ -9,6 +9,7 @@ const nextConfig: NextConfig = { }, experimental: { ppr: "incremental", + nodeMiddleware: true, }, }; diff --git a/examples/experimental/src/middleware.ts b/examples/experimental/src/middleware.ts new file mode 100644 index 000000000..ec8540434 --- /dev/null +++ b/examples/experimental/src/middleware.ts @@ -0,0 +1,27 @@ +import { type NextRequest, NextResponse } from "next/server"; +import crypto from "node:crypto"; + +export default function middleware(request: NextRequest) { + if (request.nextUrl.pathname === "/api/hello") { + return NextResponse.json({ + name: "World", + }); + } + if (request.nextUrl.pathname === "/redirect") { + return NextResponse.redirect(new URL("/", request.url)); + } + if (request.nextUrl.pathname === "/rewrite") { + return NextResponse.rewrite(new URL("/", request.url)); + } + + return NextResponse.next({ + headers: { + "x-middleware-test": "1", + "x-random-node": crypto.randomUUID(), + }, + }); +} + +export const config = { + runtime: "nodejs", +}; diff --git a/packages/tests-e2e/tests/experimental/nodeMiddleware.test.ts b/packages/tests-e2e/tests/experimental/nodeMiddleware.test.ts new file mode 100644 index 000000000..b679776a6 --- /dev/null +++ b/packages/tests-e2e/tests/experimental/nodeMiddleware.test.ts @@ -0,0 +1,29 @@ +import { expect, test } from "@playwright/test"; + +test("Node middleware should add headers", async ({ request }) => { + const resp = await request.get("/"); + expect(resp.status()).toEqual(200); + const headers = resp.headers(); + expect(headers["x-middleware-test"]).toEqual("1"); + expect(headers["x-random-node"]).toBeDefined(); +}); + +test("Node middleware should return json", async ({ request }) => { + const resp = await request.get("/api/hello"); + expect(resp.status()).toEqual(200); + const json = await resp.json(); + expect(json).toEqual({ name: "World" }); +}); + +test("Node middleware should redirect", async ({ page }) => { + await page.goto("/redirect"); + await page.waitForURL("/"); + const el = page.getByText("Incremental PPR"); + await expect(el).toBeVisible(); +}); + +test("Node middleware should rewrite", async ({ page }) => { + await page.goto("/rewrite"); + const el = page.getByText("Incremental PPR"); + await expect(el).toBeVisible(); +}); From 3fc652e05a1968d65392e22e37ed21708f24613f Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Fri, 18 Apr 2025 13:32:41 +0200 Subject: [PATCH 05/14] lint --- examples/experimental/src/middleware.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/experimental/src/middleware.ts b/examples/experimental/src/middleware.ts index ec8540434..bb097d692 100644 --- a/examples/experimental/src/middleware.ts +++ b/examples/experimental/src/middleware.ts @@ -1,5 +1,5 @@ -import { type NextRequest, NextResponse } from "next/server"; import crypto from "node:crypto"; +import { type NextRequest, NextResponse } from "next/server"; export default function middleware(request: NextRequest) { if (request.nextUrl.pathname === "/api/hello") { From 46b97390b4bcb1eab81176416e5e2a1fa7bf49db Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Fri, 18 Apr 2025 13:42:59 +0200 Subject: [PATCH 06/14] bump to latest canary --- examples/experimental/package.json | 2 +- pnpm-lock.yaml | 82 +++++++++++++++--------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/examples/experimental/package.json b/examples/experimental/package.json index f47bcbc63..795194259 100644 --- a/examples/experimental/package.json +++ b/examples/experimental/package.json @@ -11,7 +11,7 @@ "clean": "rm -rf .turbo node_modules .next .open-next" }, "dependencies": { - "next": "15.3.1-canary.8", + "next": "15.3.1-canary.13", "react": "catalog:", "react-dom": "catalog:" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7813c5597..9f216fbce 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -140,8 +140,8 @@ importers: examples/experimental: dependencies: next: - specifier: 15.3.1-canary.8 - version: 15.3.1-canary.8(@playwright/test@1.49.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + specifier: 15.3.1-canary.13 + version: 15.3.1-canary.13(@playwright/test@1.49.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) react: specifier: 'catalog:' version: 19.0.0 @@ -1906,8 +1906,8 @@ packages: '@next/env@15.2.0': resolution: {integrity: sha512-eMgJu1RBXxxqqnuRJQh5RozhskoNUDHBFybvi+Z+yK9qzKeG7dadhv/Vp1YooSZmCnegf7JxWuapV77necLZNA==} - '@next/env@15.3.1-canary.8': - resolution: {integrity: sha512-ShZTo0hNhbTRrp7k6oUDSck4Xx4hhfSeLBp35jvGaw1QMZzWYr5v/oc0kEt0bfMdl+833flwKV7kFR3BnrULfg==} + '@next/env@15.3.1-canary.13': + resolution: {integrity: sha512-BgYTh0j+eFPpYUI8u8RUiJiNpyGXZVVpC3t+/JlbBvD2ZN68cIHiyR+5+vX9koc0JbxYn5nR65s0AgXzOKod1g==} '@next/swc-darwin-arm64@15.2.0': resolution: {integrity: sha512-rlp22GZwNJjFCyL7h5wz9vtpBVuCt3ZYjFWpEPBGzG712/uL1bbSkS675rVAUCRZ4hjoTJ26Q7IKhr5DfJrHDA==} @@ -1915,8 +1915,8 @@ packages: cpu: [arm64] os: [darwin] - '@next/swc-darwin-arm64@15.3.1-canary.8': - resolution: {integrity: sha512-ZaDynM+pbrnLLlBAxH/CDGp9KN79OFrLcT1ejlWyo86V3SS9Gyqr4nmTuvTevByTTpr1VHReQel8Zbq0Pttu7Q==} + '@next/swc-darwin-arm64@15.3.1-canary.13': + resolution: {integrity: sha512-UbNA7Ox/5k6Tev0UKJNCRp1Gd+b15tL/ATW7WGvmBe8zeszQEn/U9ItML4hj2KkAmEKj9PJdh0uytQgXeAoBcQ==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] @@ -1927,8 +1927,8 @@ packages: cpu: [x64] os: [darwin] - '@next/swc-darwin-x64@15.3.1-canary.8': - resolution: {integrity: sha512-BsMR8WqeCDAX8C9RYAO8TI4ttpuqKk2oYMb1+bCrOYi857SMfB4vWD4PWmMvj7mwFXGqrxly4W6CBQlD66A+fg==} + '@next/swc-darwin-x64@15.3.1-canary.13': + resolution: {integrity: sha512-WBzNHBKbffGQbV4EBt5hwSJsmJblBEvHWydqZ2DeabwxOFpw4DZrEyRNsP3Vhiu40wSV/vpwjTbNtLoIs8Ocbg==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] @@ -1939,8 +1939,8 @@ packages: cpu: [arm64] os: [linux] - '@next/swc-linux-arm64-gnu@15.3.1-canary.8': - resolution: {integrity: sha512-xL+K2SW+/46j/KnKNf1gizM1bxwcEaE56eCEG9RPoYS/lfxHLuHcR9O2MlcPI90g/rIN2HXmHeuKRbXbnVy15g==} + '@next/swc-linux-arm64-gnu@15.3.1-canary.13': + resolution: {integrity: sha512-vDZGVhN2KVmxBfuK/xvFTPj3XpylpPKKzP8XFM2m0GI4NUqtLRIjKvd4OyrsuB1NRaIRfchl5iIGh23v2om+Pw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -1951,8 +1951,8 @@ packages: cpu: [arm64] os: [linux] - '@next/swc-linux-arm64-musl@15.3.1-canary.8': - resolution: {integrity: sha512-bzXlCUXkjIRsMTb6rr7OsWEQmdO2rZgKijnMGBJzEpa9ROq95VJTF+rdyrLmHuc4fPsAGDn/C18V3E1YOi4ipQ==} + '@next/swc-linux-arm64-musl@15.3.1-canary.13': + resolution: {integrity: sha512-dNcky0UM/6/M2xK0J4ecmb/wo1t4h0o7L5vP6dSjPZk2tCXZf98+++XqYZiBIv6DVvJck3oS85x7CcmCRZfRrw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -1963,8 +1963,8 @@ packages: cpu: [x64] os: [linux] - '@next/swc-linux-x64-gnu@15.3.1-canary.8': - resolution: {integrity: sha512-snbPQ9th7eoYYMZpNGhEvX4EbqGjjkiXzTEm2F/oDadlZR2wI6egtfQHiZqeczL7XwG3M66hBJ1/U20wdTDtvA==} + '@next/swc-linux-x64-gnu@15.3.1-canary.13': + resolution: {integrity: sha512-yTvXBe0AbRwq3jj6QLsMej9dRrXTtlPzS78IKU3Pr+uqY4DwXqeuuvYjEN8VkmD/R260HaFzAecQIdxDN+k9Mw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -1975,8 +1975,8 @@ packages: cpu: [x64] os: [linux] - '@next/swc-linux-x64-musl@15.3.1-canary.8': - resolution: {integrity: sha512-5hmcaGazc3w6rg/gbQOrmuw0kKShf4Egs0JlUPop/ZiRDfZO5KlyrGY0hUD+2pLG7Yx3B/fTbj86cHKfQZDMBw==} + '@next/swc-linux-x64-musl@15.3.1-canary.13': + resolution: {integrity: sha512-Qvw7CEqlfXLFjoAX2Q3jaM6RG/j3r4Mrp3/ZOo3OWS5MztjDBpxMst/y0EP1bgJCOyw/gxdzSArdQVVjLSKeeQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -1987,8 +1987,8 @@ packages: cpu: [arm64] os: [win32] - '@next/swc-win32-arm64-msvc@15.3.1-canary.8': - resolution: {integrity: sha512-t6uwWC/UbQ8CQGyBVbEmpcJC41yAvz2eZZGec9EoO0ZyQ/fbvjOkqfPnf+WcjWifWNeuiWogjN1UBg7YK9IaVA==} + '@next/swc-win32-arm64-msvc@15.3.1-canary.13': + resolution: {integrity: sha512-0lzIvfUh5yMwEARGxscgdDf1wtkg4kkWQtAbjKvlcwYGDVkkunL6tsq8fQ6NmxTNxwFATxCIeUysuvBOeWi0LQ==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] @@ -1999,8 +1999,8 @@ packages: cpu: [x64] os: [win32] - '@next/swc-win32-x64-msvc@15.3.1-canary.8': - resolution: {integrity: sha512-93gNqVYwlr9bz6Pm5dQnqjpuOEQyvDre0+H39UqS7h2KuFh3sf2MejhAEr2uFEux4mb7TN0PlohaihO7YxJ3fw==} + '@next/swc-win32-x64-msvc@15.3.1-canary.13': + resolution: {integrity: sha512-Z1dAHpyg8OdLm3v8SHhkuqnTqT5x71eBCMNsr3kntdzzvT29HbtVMovQpG6oLmxtVqWFyR0SSs4+ukbi17cXjw==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -4443,8 +4443,8 @@ packages: sass: optional: true - next@15.3.1-canary.8: - resolution: {integrity: sha512-Of5a3BTTIl/iUvL2a9Jh7m7G/H8z4Pj5Vs54CLvcdadokxSNgLOpjzbDgFR8J4PawLx6+MOMy19m9Cvr6EPGug==} + next@15.3.1-canary.13: + resolution: {integrity: sha512-LC8RQrWYsgD7639DRruitJ7x2HAGLFxAFXY6B6xwYQEkJNK3aeWxZyVYs8fIfXYscRqZtJXPc1EJy03xDuseyA==} engines: {node: ^18.18.0 || ^19.8.0 || >= 20.0.0} hasBin: true peerDependencies: @@ -8316,54 +8316,54 @@ snapshots: '@next/env@15.2.0': {} - '@next/env@15.3.1-canary.8': {} + '@next/env@15.3.1-canary.13': {} '@next/swc-darwin-arm64@15.2.0': optional: true - '@next/swc-darwin-arm64@15.3.1-canary.8': + '@next/swc-darwin-arm64@15.3.1-canary.13': optional: true '@next/swc-darwin-x64@15.2.0': optional: true - '@next/swc-darwin-x64@15.3.1-canary.8': + '@next/swc-darwin-x64@15.3.1-canary.13': optional: true '@next/swc-linux-arm64-gnu@15.2.0': optional: true - '@next/swc-linux-arm64-gnu@15.3.1-canary.8': + '@next/swc-linux-arm64-gnu@15.3.1-canary.13': optional: true '@next/swc-linux-arm64-musl@15.2.0': optional: true - '@next/swc-linux-arm64-musl@15.3.1-canary.8': + '@next/swc-linux-arm64-musl@15.3.1-canary.13': optional: true '@next/swc-linux-x64-gnu@15.2.0': optional: true - '@next/swc-linux-x64-gnu@15.3.1-canary.8': + '@next/swc-linux-x64-gnu@15.3.1-canary.13': optional: true '@next/swc-linux-x64-musl@15.2.0': optional: true - '@next/swc-linux-x64-musl@15.3.1-canary.8': + '@next/swc-linux-x64-musl@15.3.1-canary.13': optional: true '@next/swc-win32-arm64-msvc@15.2.0': optional: true - '@next/swc-win32-arm64-msvc@15.3.1-canary.8': + '@next/swc-win32-arm64-msvc@15.3.1-canary.13': optional: true '@next/swc-win32-x64-msvc@15.2.0': optional: true - '@next/swc-win32-x64-msvc@15.3.1-canary.8': + '@next/swc-win32-x64-msvc@15.3.1-canary.13': optional: true '@node-minify/core@8.0.6': @@ -11282,9 +11282,9 @@ snapshots: - '@babel/core' - babel-plugin-macros - next@15.3.1-canary.8(@playwright/test@1.49.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0): + next@15.3.1-canary.13(@playwright/test@1.49.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0): dependencies: - '@next/env': 15.3.1-canary.8 + '@next/env': 15.3.1-canary.13 '@swc/counter': 0.1.3 '@swc/helpers': 0.5.15 busboy: 1.6.0 @@ -11294,14 +11294,14 @@ snapshots: react-dom: 19.0.0(react@19.0.0) styled-jsx: 5.1.6(react@19.0.0) optionalDependencies: - '@next/swc-darwin-arm64': 15.3.1-canary.8 - '@next/swc-darwin-x64': 15.3.1-canary.8 - '@next/swc-linux-arm64-gnu': 15.3.1-canary.8 - '@next/swc-linux-arm64-musl': 15.3.1-canary.8 - '@next/swc-linux-x64-gnu': 15.3.1-canary.8 - '@next/swc-linux-x64-musl': 15.3.1-canary.8 - '@next/swc-win32-arm64-msvc': 15.3.1-canary.8 - '@next/swc-win32-x64-msvc': 15.3.1-canary.8 + '@next/swc-darwin-arm64': 15.3.1-canary.13 + '@next/swc-darwin-x64': 15.3.1-canary.13 + '@next/swc-linux-arm64-gnu': 15.3.1-canary.13 + '@next/swc-linux-arm64-musl': 15.3.1-canary.13 + '@next/swc-linux-x64-gnu': 15.3.1-canary.13 + '@next/swc-linux-x64-musl': 15.3.1-canary.13 + '@next/swc-win32-arm64-msvc': 15.3.1-canary.13 + '@next/swc-win32-x64-msvc': 15.3.1-canary.13 '@playwright/test': 1.49.1 sharp: 0.34.1 transitivePeerDependencies: From b4de3cc4cd76cd02e44004f3e7c0421a3514db36 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Wed, 16 Apr 2025 14:19:26 +0200 Subject: [PATCH 07/14] pass revalidate for isr incremental cache --- packages/open-next/src/adapters/cache.ts | 27 ++++++++++++- packages/open-next/src/types/cache.ts | 48 +++++++++++++++++++---- packages/open-next/src/types/overrides.ts | 7 +++- 3 files changed, 73 insertions(+), 9 deletions(-) diff --git a/packages/open-next/src/adapters/cache.ts b/packages/open-next/src/adapters/cache.ts index fe573f7d7..e7ab10157 100644 --- a/packages/open-next/src/adapters/cache.ts +++ b/packages/open-next/src/adapters/cache.ts @@ -207,6 +207,7 @@ export default class Cache { if (data === null || data === undefined) { await globalThis.incrementalCache.delete(key); } else { + const revalidate = this.extractRevalidateForSet(ctx); switch (data.kind) { case "ROUTE": case "APP_ROUTE": { @@ -224,6 +225,7 @@ export default class Cache { status, headers, }, + revalidate, }, false, ); @@ -244,6 +246,7 @@ export default class Cache { status, headers, }, + revalidate, }, false, ); @@ -254,6 +257,7 @@ export default class Cache { type: "page", html, json: pageData, + revalidate, }, false, ); @@ -272,6 +276,7 @@ export default class Cache { status, headers, }, + revalidate, }, false, ); @@ -286,6 +291,7 @@ export default class Cache { { type: "redirect", props: data.props, + revalidate, }, false, ); @@ -424,7 +430,8 @@ export default class Cache { // If we use an in house version of getDerivedTags in build we should use it here instead of next's one const derivedTags: string[] = data?.kind === "FETCH" - ? (ctx?.tags ?? data?.data?.tags ?? []) // before version 14 next.js used data?.data?.tags so we keep it for backward compatibility + ? //@ts-expect-error - On older versions of next, ctx was a number, but for these cases we use data?.data?.tags + (ctx?.tags ?? data?.data?.tags ?? []) // before version 14 next.js used data?.data?.tags so we keep it for backward compatibility : data?.kind === "PAGE" ? (data.headers?.["x-next-cache-tags"]?.split(",") ?? []) : []; @@ -446,4 +453,22 @@ export default class Cache { ); } } + + private extractRevalidateForSet( + ctx?: IncrementalCacheContext, + ): number | false | undefined { + if (ctx === undefined) { + return undefined; + } + if (typeof ctx === "number" || ctx === false) { + return ctx; + } + if ("revalidate" in ctx) { + return ctx.revalidate; + } + if ("cacheControl" in ctx) { + return ctx.cacheControl?.revalidate; + } + return undefined; + } } diff --git a/packages/open-next/src/types/cache.ts b/packages/open-next/src/types/cache.ts index b37997f38..ebd19de0f 100644 --- a/packages/open-next/src/types/cache.ts +++ b/packages/open-next/src/types/cache.ts @@ -98,10 +98,44 @@ export type TagCacheMetaFile = { revalidatedAt: { N: string }; }; -export type IncrementalCacheContext = { - revalidate?: number | false | undefined; - fetchCache?: boolean | undefined; - fetchUrl?: string | undefined; - fetchIdx?: number | undefined; - tags?: string[] | undefined; -}; +// Cache context since https://github.com/vercel/next.js/pull/76207 +interface SetIncrementalFetchCacheContext { + fetchCache: true; + fetchUrl?: string; + fetchIdx?: number; + tags?: string[]; +} + +interface SetIncrementalResponseCacheContext { + fetchCache?: false; + cacheControl?: { + revalidate: number | false; + expire?: number; + }; + + /** + * True if the route is enabled for PPR. + */ + isRoutePPREnabled?: boolean; + + /** + * True if this is a fallback request. + */ + isFallback?: boolean; +} + +// Before #76207 revalidate was passed this way +interface SetIncrementalCacheContext { + revalidate?: number | false; + isRoutePPREnabled?: boolean; + isFallback?: boolean; +} + +// Before https://github.com/vercel/next.js/pull/53321 context on set was just the revalidate +type OldSetIncrementalCacheContext = number | false | undefined; + +export type IncrementalCacheContext = + | OldSetIncrementalCacheContext + | SetIncrementalCacheContext + | SetIncrementalFetchCacheContext + | SetIncrementalResponseCacheContext; diff --git a/packages/open-next/src/types/overrides.ts b/packages/open-next/src/types/overrides.ts index 81325c8b8..8363835c4 100644 --- a/packages/open-next/src/types/overrides.ts +++ b/packages/open-next/src/types/overrides.ts @@ -79,7 +79,12 @@ export type WithLastModified = { export type CacheValue = (IsFetch extends true ? CachedFetchValue - : CachedFile) & { revalidate?: number | false }; + : CachedFile) & { + /** + * This is available for page cache entry, but only at runtime. + */ + revalidate?: number | false; +}; export type IncrementalCache = { get( From 48c5da61f1eda9e3923132d43abf157aca335694 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Wed, 16 Apr 2025 14:46:41 +0200 Subject: [PATCH 08/14] changeset --- .changeset/lucky-ghosts-knock.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lucky-ghosts-knock.md diff --git a/.changeset/lucky-ghosts-knock.md b/.changeset/lucky-ghosts-knock.md new file mode 100644 index 000000000..d973d0f52 --- /dev/null +++ b/.changeset/lucky-ghosts-knock.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +pass revalidate for ISR/SSG cache From dc8083ced678c453a21a3cfc02cb7a2b38b49162 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Mon, 7 Apr 2025 14:02:35 +0200 Subject: [PATCH 09/14] basic implementation for composable cache --- .../src/adapters/composable-cache.ts | 55 +++++++++++++++++++ packages/open-next/src/build/compileCache.ts | 40 +++++++++++++- .../open-next/src/build/createServerBundle.ts | 13 +++++ packages/open-next/src/core/util.ts | 7 +++ .../overrides/tagCache/dynamodb-nextMode.ts | 4 ++ packages/open-next/src/types/cache.ts | 2 + packages/open-next/src/types/overrides.ts | 2 + 7 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 packages/open-next/src/adapters/composable-cache.ts diff --git a/packages/open-next/src/adapters/composable-cache.ts b/packages/open-next/src/adapters/composable-cache.ts new file mode 100644 index 000000000..b05b53fbf --- /dev/null +++ b/packages/open-next/src/adapters/composable-cache.ts @@ -0,0 +1,55 @@ +import type { + ComposableCacheEntry, + ComposableCacheHandler, + StoredComposableCacheEntry, +} from "types/cache"; +import { fromReadableStream, toReadableStream } from "utils/stream"; +import { debug } from "./logger"; + +export default { + async get(cacheKey: string) { + try { + // TODO: update the type of the incremental cache + const result = (await globalThis.incrementalCache.get( + cacheKey, + true, + )) as unknown as StoredComposableCacheEntry; + + debug("composable cache result", result); + + return { + ...result.value, + value: toReadableStream(result.value.value), + }; + } catch (e) { + debug("Cannot read composable cache entry"); + return undefined; + } + }, + + async set(cacheKey: string, pendingEntry: Promise) { + const entry = await pendingEntry; + const valueToStore = await fromReadableStream(entry.value); + await globalThis.incrementalCache.set(cacheKey, { + ...entry, + value: valueToStore, + } as any); + }, + + async refreshTags() { + // We don't do anything for now, do we want to do something here ??? + return; + }, + async getExpiration(...tags: string[]) { + if (globalThis.tagCache.mode === "nextMode") { + return globalThis.tagCache.getLastRevalidated(tags); + } + //TODO: Not supported for now - I'll need to figure out a way, maybe we'd want to merge both type into one + return 0; + }, + async expireTags(...tags: string[]) { + if (globalThis.tagCache.mode === "nextMode") { + return globalThis.tagCache.writeTags(tags); + } + }, +} satisfies ComposableCacheHandler; diff --git a/packages/open-next/src/build/compileCache.ts b/packages/open-next/src/build/compileCache.ts index fa30f2e3a..bf4af8412 100644 --- a/packages/open-next/src/build/compileCache.ts +++ b/packages/open-next/src/build/compileCache.ts @@ -15,7 +15,11 @@ export function compileCache( ) { const { config } = options; const ext = format === "cjs" ? "cjs" : "mjs"; - const outFile = path.join(options.buildDir, `cache.${ext}`); + const compiledCacheFile = path.join(options.buildDir, `cache.${ext}`); + const compiledComposableCacheFile = path.join( + options.buildDir, + `composable-cache.${ext}`, + ); const isAfter15 = buildHelper.compareSemver( options.nextVersion, @@ -23,11 +27,37 @@ export function compileCache( "15.0.0", ); + // Normal cache buildHelper.esbuildSync( { external: ["next", "styled-jsx", "react", "@aws-sdk/*"], entryPoints: [path.join(options.openNextDistDir, "adapters", "cache.js")], - outfile: outFile, + outfile: compiledCacheFile, + target: ["node18"], + format, + banner: { + js: [ + `globalThis.disableIncrementalCache = ${ + config.dangerous?.disableIncrementalCache ?? false + };`, + `globalThis.disableDynamoDBCache = ${ + config.dangerous?.disableTagCache ?? false + };`, + `globalThis.isNextAfter15 = ${isAfter15};`, + ].join(""), + }, + }, + options, + ); + + // Composable cache + buildHelper.esbuildSync( + { + external: ["next", "styled-jsx", "react", "@aws-sdk/*"], + entryPoints: [ + path.join(options.openNextDistDir, "adapters", "composable-cache.js"), + ], + outfile: compiledComposableCacheFile, target: ["node18"], format, banner: { @@ -44,5 +74,9 @@ export function compileCache( }, options, ); - return outFile; + + return { + cache: compiledCacheFile, + composableCache: compiledComposableCacheFile, + }; } diff --git a/packages/open-next/src/build/createServerBundle.ts b/packages/open-next/src/build/createServerBundle.ts index 694ef50c9..997166ec8 100644 --- a/packages/open-next/src/build/createServerBundle.ts +++ b/packages/open-next/src/build/createServerBundle.ts @@ -147,10 +147,16 @@ async function generateBundle( fs.mkdirSync(outPackagePath, { recursive: true }); const ext = fnOptions.runtime === "deno" ? "mjs" : "cjs"; + // Normal cache fs.copyFileSync( path.join(options.buildDir, `cache.${ext}`), path.join(outPackagePath, "cache.cjs"), ); + // Composable cache + fs.copyFileSync( + path.join(options.buildDir, `composable-cache.${ext}`), + path.join(outPackagePath, "composable-cache.cjs"), + ); if (fnOptions.runtime === "deno") { addDenoJson(outputPath, packagePath); @@ -237,6 +243,12 @@ async function generateBundle( "14.2", ); + const isAfter152 = buildHelper.compareSemver( + options.nextVersion, + ">=", + "15.2.0", + ); + const disableRouting = isBefore13413 || config.middleware?.external; const updater = new ContentUpdater(options); @@ -265,6 +277,7 @@ async function generateBundle( ...(isAfter141 ? ["experimentalIncrementalCacheHandler"] : ["stableIncrementalCache"]), + ...(isAfter152 ? [] : ["composableCache"]), ], }), diff --git a/packages/open-next/src/core/util.ts b/packages/open-next/src/core/util.ts index 876710d2a..d6b89d38a 100644 --- a/packages/open-next/src/core/util.ts +++ b/packages/open-next/src/core/util.ts @@ -25,6 +25,7 @@ overrideNextjsRequireHooks(NextConfig); applyNextjsRequireHooksOverride(); //#endOverride const cacheHandlerPath = require.resolve("./cache.cjs"); +const composableCacheHandlerPath = require.resolve("./composable-cache.cjs"); // @ts-ignore const nextServer = new NextServer.default({ //#override requestHandlerHost @@ -52,6 +53,12 @@ const nextServer = new NextServer.default({ //#override experimentalIncrementalCacheHandler incrementalCacheHandlerPath: cacheHandlerPath, //#endOverride + + //#override composableCache + cacheHandlers: { + default: composableCacheHandlerPath, + }, + //#endOverride }, }, customServer: false, diff --git a/packages/open-next/src/overrides/tagCache/dynamodb-nextMode.ts b/packages/open-next/src/overrides/tagCache/dynamodb-nextMode.ts index 7d16bebfc..1d4a5da38 100644 --- a/packages/open-next/src/overrides/tagCache/dynamodb-nextMode.ts +++ b/packages/open-next/src/overrides/tagCache/dynamodb-nextMode.ts @@ -71,6 +71,10 @@ function buildDynamoObject(tag: string, revalidatedAt?: number) { export default { name: "ddb-nextMode", mode: "nextMode", + getLastRevalidated: async (tags: string[]) => { + // Not supported for now + return 0; + }, hasBeenRevalidated: async (tags: string[], lastModified?: number) => { if (globalThis.openNextConfig.dangerous?.disableTagCache) { return false; diff --git a/packages/open-next/src/types/cache.ts b/packages/open-next/src/types/cache.ts index ebd19de0f..2e6e5b37c 100644 --- a/packages/open-next/src/types/cache.ts +++ b/packages/open-next/src/types/cache.ts @@ -1,3 +1,5 @@ +import type { ReadableStream } from "node:stream/web"; + interface CachedFetchValue { kind: "FETCH"; data: { diff --git a/packages/open-next/src/types/overrides.ts b/packages/open-next/src/types/overrides.ts index 8363835c4..57de7bbb2 100644 --- a/packages/open-next/src/types/overrides.ts +++ b/packages/open-next/src/types/overrides.ts @@ -129,6 +129,8 @@ Cons : */ export type NextModeTagCache = BaseTagCache & { mode: "nextMode"; + // Necessary for the composable cache + getLastRevalidated(tags: string[]): Promise; hasBeenRevalidated(tags: string[], lastModified?: number): Promise; writeTags(tags: string[]): Promise; // Optional method to get paths by tags From 9fb80b2026be28f7afac1357d4f7294a6d46c5a1 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Wed, 9 Apr 2025 10:58:18 +0200 Subject: [PATCH 10/14] updated types --- packages/open-next/src/adapters/cache.ts | 16 ++++----- .../src/adapters/composable-cache.ts | 28 ++++++++------- .../src/core/routing/cacheInterceptor.ts | 2 +- .../incrementalCache/multi-tier-ddb-s3.ts | 13 +++++-- .../src/overrides/incrementalCache/s3-lite.ts | 24 +++++-------- .../src/overrides/incrementalCache/s3.ts | 8 ++--- packages/open-next/src/types/cache.ts | 26 +++++++++++++- packages/open-next/src/types/overrides.ts | 36 +++++++++++-------- packages/open-next/src/utils/cache.ts | 2 +- .../tests-unit/tests/adapters/cache.test.ts | 14 ++++---- 10 files changed, 101 insertions(+), 68 deletions(-) diff --git a/packages/open-next/src/adapters/cache.ts b/packages/open-next/src/adapters/cache.ts index e7ab10157..48a9d067d 100644 --- a/packages/open-next/src/adapters/cache.ts +++ b/packages/open-next/src/adapters/cache.ts @@ -57,7 +57,7 @@ export default class Cache { async getFetchCache(key: string, softTags?: string[], tags?: string[]) { debug("get fetch cache", { key, softTags, tags }); try { - const cachedEntry = await globalThis.incrementalCache.get(key, true); + const cachedEntry = await globalThis.incrementalCache.get(key, "fetch"); if (cachedEntry?.value === undefined) return null; @@ -107,7 +107,7 @@ export default class Cache { async getIncrementalCache(key: string): Promise { try { - const cachedEntry = await globalThis.incrementalCache.get(key, false); + const cachedEntry = await globalThis.incrementalCache.get(key, "cache"); if (!cachedEntry?.value) { return null; @@ -227,7 +227,7 @@ export default class Cache { }, revalidate, }, - false, + "cache", ); break; } @@ -248,7 +248,7 @@ export default class Cache { }, revalidate, }, - false, + "cache", ); } else { await globalThis.incrementalCache.set( @@ -259,7 +259,7 @@ export default class Cache { json: pageData, revalidate, }, - false, + "cache", ); } break; @@ -278,12 +278,12 @@ export default class Cache { }, revalidate, }, - false, + "cache", ); break; } case "FETCH": - await globalThis.incrementalCache.set(key, data, true); + await globalThis.incrementalCache.set(key, data, "fetch"); break; case "REDIRECT": await globalThis.incrementalCache.set( @@ -293,7 +293,7 @@ export default class Cache { props: data.props, revalidate, }, - false, + "cache", ); break; case "IMAGE": diff --git a/packages/open-next/src/adapters/composable-cache.ts b/packages/open-next/src/adapters/composable-cache.ts index b05b53fbf..019857b14 100644 --- a/packages/open-next/src/adapters/composable-cache.ts +++ b/packages/open-next/src/adapters/composable-cache.ts @@ -1,19 +1,17 @@ -import type { - ComposableCacheEntry, - ComposableCacheHandler, - StoredComposableCacheEntry, -} from "types/cache"; +import type { ComposableCacheEntry, ComposableCacheHandler } from "types/cache"; import { fromReadableStream, toReadableStream } from "utils/stream"; import { debug } from "./logger"; export default { async get(cacheKey: string) { try { - // TODO: update the type of the incremental cache - const result = (await globalThis.incrementalCache.get( + const result = await globalThis.incrementalCache.get( cacheKey, - true, - )) as unknown as StoredComposableCacheEntry; + "composable", + ); + if (!result || !result.value?.value) { + return undefined; + } debug("composable cache result", result); @@ -30,10 +28,14 @@ export default { async set(cacheKey: string, pendingEntry: Promise) { const entry = await pendingEntry; const valueToStore = await fromReadableStream(entry.value); - await globalThis.incrementalCache.set(cacheKey, { - ...entry, - value: valueToStore, - } as any); + await globalThis.incrementalCache.set( + cacheKey, + { + ...entry, + value: valueToStore, + }, + "composable", + ); }, async refreshTags() { diff --git a/packages/open-next/src/core/routing/cacheInterceptor.ts b/packages/open-next/src/core/routing/cacheInterceptor.ts index bb8814f12..9a2aaf88c 100644 --- a/packages/open-next/src/core/routing/cacheInterceptor.ts +++ b/packages/open-next/src/core/routing/cacheInterceptor.ts @@ -89,7 +89,7 @@ async function computeCacheControl( async function generateResult( event: InternalEvent, localizedPath: string, - cachedValue: CacheValue, + cachedValue: CacheValue<"cache">, lastModified?: number, ): Promise { debug("Returning result from experimental cache"); diff --git a/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts b/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts index 49c254258..5ee8bcc32 100644 --- a/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts +++ b/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts @@ -1,4 +1,8 @@ -import type { CacheValue, IncrementalCache } from "types/overrides"; +import type { + CacheEntryType, + CacheValue, + IncrementalCache, +} from "types/overrides"; import { customFetchClient } from "utils/fetch"; import { LRUCache } from "utils/lru"; import { debug } from "../../adapters/logger"; @@ -50,11 +54,14 @@ const buildDynamoKey = (key: string) => { */ const multiTierCache: IncrementalCache = { name: "multi-tier-ddb-s3", - async get(key: string, isFetch?: IsFetch) { + async get( + key: string, + isFetch?: CacheType, + ) { // First we check the local cache const localCacheEntry = localCache.get(key) as | { - value: CacheValue; + value: CacheValue; lastModified: number; } | undefined; diff --git a/packages/open-next/src/overrides/incrementalCache/s3-lite.ts b/packages/open-next/src/overrides/incrementalCache/s3-lite.ts index e24db620a..e2355be34 100644 --- a/packages/open-next/src/overrides/incrementalCache/s3-lite.ts +++ b/packages/open-next/src/overrides/incrementalCache/s3-lite.ts @@ -44,13 +44,10 @@ function buildS3Key(key: string, extension: Extension) { } const incrementalCache: IncrementalCache = { - async get(key, isFetch) { - const result = await awsFetch( - buildS3Key(key, isFetch ? "fetch" : "cache"), - { - method: "GET", - }, - ); + async get(key, cacheType) { + const result = await awsFetch(buildS3Key(key, cacheType ?? "cache"), { + method: "GET", + }); if (result.status === 404) { throw new IgnorableError("Not found"); @@ -66,14 +63,11 @@ const incrementalCache: IncrementalCache = { ).getTime(), }; }, - async set(key, value, isFetch): Promise { - const response = await awsFetch( - buildS3Key(key, isFetch ? "fetch" : "cache"), - { - method: "PUT", - body: JSON.stringify(value), - }, - ); + async set(key, value, cacheType): Promise { + const response = await awsFetch(buildS3Key(key, cacheType ?? "cache"), { + method: "PUT", + body: JSON.stringify(value), + }); if (response.status !== 200) { throw new RecoverableError(`Failed to set cache: ${response.status}`); } diff --git a/packages/open-next/src/overrides/incrementalCache/s3.ts b/packages/open-next/src/overrides/incrementalCache/s3.ts index 0ee7f6b51..371499209 100644 --- a/packages/open-next/src/overrides/incrementalCache/s3.ts +++ b/packages/open-next/src/overrides/incrementalCache/s3.ts @@ -40,11 +40,11 @@ function buildS3Key(key: string, extension: Extension) { } const incrementalCache: IncrementalCache = { - async get(key, isFetch) { + async get(key, cacheType) { const result = await s3Client.send( new GetObjectCommand({ Bucket: CACHE_BUCKET_NAME, - Key: buildS3Key(key, isFetch ? "fetch" : "cache"), + Key: buildS3Key(key, cacheType ?? "cache"), }), ); @@ -56,11 +56,11 @@ const incrementalCache: IncrementalCache = { lastModified: result.LastModified?.getTime(), }; }, - async set(key, value, isFetch): Promise { + async set(key, value, cacheType): Promise { await s3Client.send( new PutObjectCommand({ Bucket: CACHE_BUCKET_NAME, - Key: buildS3Key(key, isFetch ? "fetch" : "cache"), + Key: buildS3Key(key, cacheType ?? "cache"), Body: JSON.stringify(value), }), ); diff --git a/packages/open-next/src/types/cache.ts b/packages/open-next/src/types/cache.ts index 2e6e5b37c..f1582d790 100644 --- a/packages/open-next/src/types/cache.ts +++ b/packages/open-next/src/types/cache.ts @@ -81,7 +81,7 @@ export interface CacheHandlerValue { value: IncrementalCacheValue | null; } -export type Extension = "cache" | "fetch"; +export type Extension = "cache" | "fetch" | "composable"; type MetaHeaders = { "x-next-cache-tags"?: string; @@ -141,3 +141,27 @@ export type IncrementalCacheContext = | SetIncrementalCacheContext | SetIncrementalFetchCacheContext | SetIncrementalResponseCacheContext; + +export interface ComposableCacheEntry { + value: ReadableStream; + tags: string[]; + stale: number; + timestamp: number; + expire: number; + revalidate: number; +} + +export type StoredComposableCacheEntry = Omit & { + value: string; +}; + +export interface ComposableCacheHandler { + get(cacheKey: string): Promise; + set( + cacheKey: string, + pendingEntry: Promise, + ): Promise; + refreshTags(): Promise; + getExpiration(...tags: string[]): Promise; + expireTags(...tags: string[]): Promise; +} diff --git a/packages/open-next/src/types/overrides.ts b/packages/open-next/src/types/overrides.ts index 57de7bbb2..4d8eb02d9 100644 --- a/packages/open-next/src/types/overrides.ts +++ b/packages/open-next/src/types/overrides.ts @@ -1,6 +1,7 @@ import type { Readable } from "node:stream"; -import type { Meta } from "types/cache"; +import type { Extension, Meta, StoredComposableCacheEntry } from "types/cache"; + import type { BaseEventOrResult, BaseOverride, @@ -77,24 +78,29 @@ export type WithLastModified = { value?: T; }; -export type CacheValue = (IsFetch extends true - ? CachedFetchValue - : CachedFile) & { - /** - * This is available for page cache entry, but only at runtime. - */ - revalidate?: number | false; -}; +export type CacheEntryType = Extension; + +export type CacheValue = + (CacheType extends "fetch" + ? CachedFetchValue + : CacheType extends "cache" + ? CachedFile + : StoredComposableCacheEntry) & { + /** + * This is available for page cache entry, but only at runtime. + */ + revalidate?: number | false; + }; export type IncrementalCache = { - get( + get( key: string, - isFetch?: IsFetch, - ): Promise> | null>; - set( + cacheType?: CacheType, + ): Promise> | null>; + set( key: string, - value: CacheValue, - isFetch?: IsFetch, + value: CacheValue, + isFetch?: CacheType, ): Promise; delete(key: string): Promise; name: string; diff --git a/packages/open-next/src/utils/cache.ts b/packages/open-next/src/utils/cache.ts index 98c028004..5072e4bef 100644 --- a/packages/open-next/src/utils/cache.ts +++ b/packages/open-next/src/utils/cache.ts @@ -28,7 +28,7 @@ export async function hasBeenRevalidated( return _lastModified === -1; } -export function getTagsFromValue(value?: CacheValue) { +export function getTagsFromValue(value?: CacheValue<"cache">) { if (!value) { return []; } diff --git a/packages/tests-unit/tests/adapters/cache.test.ts b/packages/tests-unit/tests/adapters/cache.test.ts index 4dff3166c..e4e3977fd 100644 --- a/packages/tests-unit/tests/adapters/cache.test.ts +++ b/packages/tests-unit/tests/adapters/cache.test.ts @@ -361,7 +361,7 @@ describe("CacheHandler", () => { expect(incrementalCache.set).toHaveBeenCalledWith( "key", { type: "route", body: "{}", meta: { status: 200, headers: {} } }, - false, + "cache", ); }); @@ -382,7 +382,7 @@ describe("CacheHandler", () => { body: Buffer.from("{}").toString("base64"), meta: { status: 200, headers: { "content-type": "image/png" } }, }, - false, + "cache", ); }); @@ -402,7 +402,7 @@ describe("CacheHandler", () => { html: "", json: {}, }, - false, + "cache", ); }); @@ -423,7 +423,7 @@ describe("CacheHandler", () => { rsc: "rsc", meta: { status: 200, headers: {} }, }, - false, + "cache", ); }); @@ -444,7 +444,7 @@ describe("CacheHandler", () => { rsc: "rsc", meta: { status: 200, headers: {} }, }, - false, + "cache", ); }); @@ -474,7 +474,7 @@ describe("CacheHandler", () => { }, revalidate: 60, }, - true, + "fetch", ); }); @@ -487,7 +487,7 @@ describe("CacheHandler", () => { type: "redirect", props: {}, }, - false, + "cache", ); }); From d04372f5f53d49b71dd784f1bd0e8c6f6862e602 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Wed, 9 Apr 2025 13:05:14 +0200 Subject: [PATCH 11/14] make it work with original mode --- .../src/adapters/composable-cache.ts | 54 ++++++++++++++++++- .../src/overrides/tagCache/fs-dev.ts | 3 +- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/packages/open-next/src/adapters/composable-cache.ts b/packages/open-next/src/adapters/composable-cache.ts index 019857b14..228d8bd3b 100644 --- a/packages/open-next/src/adapters/composable-cache.ts +++ b/packages/open-next/src/adapters/composable-cache.ts @@ -15,6 +15,28 @@ export default { debug("composable cache result", result); + // We need to check if the tags associated with this entry has been revalidated + if ( + globalThis.tagCache.mode === "nextMode" && + result.value.tags.length > 0 + ) { + const hasBeenRevalidated = await globalThis.tagCache.hasBeenRevalidated( + result.value.tags, + result.lastModified, + ); + if (hasBeenRevalidated) return undefined; + } else if ( + globalThis.tagCache.mode === "original" || + globalThis.tagCache.mode === undefined + ) { + const hasBeenRevalidated = + (await globalThis.tagCache.getLastModified( + cacheKey, + result.lastModified, + )) === -1; + if (hasBeenRevalidated) return undefined; + } + return { ...result.value, value: toReadableStream(result.value.value), @@ -36,6 +58,15 @@ export default { }, "composable", ); + if (globalThis.tagCache.mode === "original") { + const storedTags = await globalThis.tagCache.getByPath(cacheKey); + const tagsToWrite = entry.tags.filter((tag) => !storedTags.includes(tag)); + if (tagsToWrite.length > 0) { + await globalThis.tagCache.writeTags( + tagsToWrite.map((tag) => ({ tag, path: cacheKey })), + ); + } + } }, async refreshTags() { @@ -46,12 +77,33 @@ export default { if (globalThis.tagCache.mode === "nextMode") { return globalThis.tagCache.getLastRevalidated(tags); } - //TODO: Not supported for now - I'll need to figure out a way, maybe we'd want to merge both type into one + // We always return 0 here, original tag cache are handled directly in the get part + // TODO: We need to test this more, i'm not entirely sure that this is working as expected return 0; }, async expireTags(...tags: string[]) { if (globalThis.tagCache.mode === "nextMode") { return globalThis.tagCache.writeTags(tags); } + const tagCache = globalThis.tagCache; + const revalidatedAt = Date.now(); + // For the original mode, we have more work to do here. + // We need to find all paths linked to to these tags + const pathsToUpdate = await Promise.all( + tags.map(async (tag) => { + const paths = await tagCache.getByTag(tag); + return paths.map((path) => ({ + path, + tag, + revalidatedAt, + })); + }), + ); + // We need to deduplicate paths, we use a set for that + const setToWrite = new Set<{ path: string; tag: string }>(); + for (const entry of pathsToUpdate.flat()) { + setToWrite.add(entry); + } + await globalThis.tagCache.writeTags(Array.from(setToWrite)); }, } satisfies ComposableCacheHandler; diff --git a/packages/open-next/src/overrides/tagCache/fs-dev.ts b/packages/open-next/src/overrides/tagCache/fs-dev.ts index 4de4d0a75..f6f61e992 100644 --- a/packages/open-next/src/overrides/tagCache/fs-dev.ts +++ b/packages/open-next/src/overrides/tagCache/fs-dev.ts @@ -2,6 +2,7 @@ import type { TagCache } from "types/overrides"; import fs from "node:fs"; +// TODO: fix this for monorepo const tagFile = "../../dynamodb-provider/dynamodb-cache.json"; const tagContent = fs.readFileSync(tagFile, "utf-8"); @@ -44,7 +45,7 @@ const tagCache: TagCache = { newTags.map((tag) => ({ tag: { S: tag.tag }, path: { S: tag.path }, - revalidatedAt: { N: String(tag.revalidatedAt) }, + revalidatedAt: { N: String(tag.revalidatedAt ?? 1) }, })), ); }, From beac4cfe887d980b42e2db2868e2dd31c566ac47 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Fri, 18 Apr 2025 15:09:05 +0200 Subject: [PATCH 12/14] add e2e test --- examples/experimental/next.config.ts | 1 + .../src/app/api/revalidate/route.ts | 6 +++ .../src/app/use-cache/isr/page.tsx | 17 +++++++ .../experimental/src/app/use-cache/layout.tsx | 13 ++++++ .../src/app/use-cache/ssr/page.tsx | 20 ++++++++ .../experimental/src/components/cached.tsx | 24 ++++++++++ .../src/adapters/composable-cache.ts | 6 +++ packages/open-next/src/types/cache.ts | 4 ++ .../tests/experimental/use-cache.test.ts | 46 +++++++++++++++++++ 9 files changed, 137 insertions(+) create mode 100644 examples/experimental/src/app/api/revalidate/route.ts create mode 100644 examples/experimental/src/app/use-cache/isr/page.tsx create mode 100644 examples/experimental/src/app/use-cache/layout.tsx create mode 100644 examples/experimental/src/app/use-cache/ssr/page.tsx create mode 100644 examples/experimental/src/components/cached.tsx create mode 100644 packages/tests-e2e/tests/experimental/use-cache.test.ts diff --git a/examples/experimental/next.config.ts b/examples/experimental/next.config.ts index c3fcdb402..c6ebc28eb 100644 --- a/examples/experimental/next.config.ts +++ b/examples/experimental/next.config.ts @@ -10,6 +10,7 @@ const nextConfig: NextConfig = { experimental: { ppr: "incremental", nodeMiddleware: true, + dynamicIO: true, }, }; diff --git a/examples/experimental/src/app/api/revalidate/route.ts b/examples/experimental/src/app/api/revalidate/route.ts new file mode 100644 index 000000000..da6b1e027 --- /dev/null +++ b/examples/experimental/src/app/api/revalidate/route.ts @@ -0,0 +1,6 @@ +import { revalidateTag } from "next/cache"; + +export function GET() { + revalidateTag("fullyTagged"); + return new Response("DONE"); +} diff --git a/examples/experimental/src/app/use-cache/isr/page.tsx b/examples/experimental/src/app/use-cache/isr/page.tsx new file mode 100644 index 000000000..dd02f8a63 --- /dev/null +++ b/examples/experimental/src/app/use-cache/isr/page.tsx @@ -0,0 +1,17 @@ +import { FullyCachedComponent, ISRComponent } from "@/components/cached"; +import { Suspense } from "react"; + +export default async function Page() { + // Not working for now, need a patch in next to disable full revalidation during ISR revalidation + return ( +
+

Cache

+ Loading...

}> + +
+ Loading...

}> + +
+
+ ); +} diff --git a/examples/experimental/src/app/use-cache/layout.tsx b/examples/experimental/src/app/use-cache/layout.tsx new file mode 100644 index 000000000..b21b82fe6 --- /dev/null +++ b/examples/experimental/src/app/use-cache/layout.tsx @@ -0,0 +1,13 @@ +import { Suspense } from "react"; + +export default function Layout({ + children, +}: { + children: React.ReactNode; +}) { + return ( +
+ Loading...

}>{children}
+
+ ); +} diff --git a/examples/experimental/src/app/use-cache/ssr/page.tsx b/examples/experimental/src/app/use-cache/ssr/page.tsx new file mode 100644 index 000000000..41a413d1b --- /dev/null +++ b/examples/experimental/src/app/use-cache/ssr/page.tsx @@ -0,0 +1,20 @@ +import { FullyCachedComponent, ISRComponent } from "@/components/cached"; +import { headers } from "next/headers"; +import { Suspense } from "react"; + +export default async function Page() { + // To opt into SSR + const _headers = await headers(); + return ( +
+

Cache

+

{_headers.get("accept") ?? "No accept headers"}

+ Loading...

}> + +
+ Loading...

}> + +
+
+ ); +} diff --git a/examples/experimental/src/components/cached.tsx b/examples/experimental/src/components/cached.tsx new file mode 100644 index 000000000..34db53992 --- /dev/null +++ b/examples/experimental/src/components/cached.tsx @@ -0,0 +1,24 @@ +import { unstable_cacheTag, unstable_cacheLife } from "next/cache"; + +export async function FullyCachedComponent() { + "use cache"; + unstable_cacheTag("fullyTagged"); + return ( +
+

{Date.now()}

+
+ ); +} + +export async function ISRComponent() { + "use cache"; + unstable_cacheLife({ + stale: 1, + revalidate: 5, + }); + return ( +
+

{Date.now()}

+
+ ); +} diff --git a/packages/open-next/src/adapters/composable-cache.ts b/packages/open-next/src/adapters/composable-cache.ts index 228d8bd3b..72d624569 100644 --- a/packages/open-next/src/adapters/composable-cache.ts +++ b/packages/open-next/src/adapters/composable-cache.ts @@ -106,4 +106,10 @@ export default { } await globalThis.tagCache.writeTags(Array.from(setToWrite)); }, + + // This one is necessary for older versions of next + async receiveExpiredTags(...tags: string[]) { + // This function does absolutely nothing + return; + }, } satisfies ComposableCacheHandler; diff --git a/packages/open-next/src/types/cache.ts b/packages/open-next/src/types/cache.ts index f1582d790..a2de4d2c3 100644 --- a/packages/open-next/src/types/cache.ts +++ b/packages/open-next/src/types/cache.ts @@ -164,4 +164,8 @@ export interface ComposableCacheHandler { refreshTags(): Promise; getExpiration(...tags: string[]): Promise; expireTags(...tags: string[]): Promise; + /** + * This function is only there for older versions and do nothing + */ + receiveExpiredTags(...tags: string[]): Promise; } diff --git a/packages/tests-e2e/tests/experimental/use-cache.test.ts b/packages/tests-e2e/tests/experimental/use-cache.test.ts new file mode 100644 index 000000000..1c750baf3 --- /dev/null +++ b/packages/tests-e2e/tests/experimental/use-cache.test.ts @@ -0,0 +1,46 @@ +import { test, expect } from "@playwright/test"; + +test("cached component should work in ssr", async ({ page }) => { + await page.goto("/use-cache/ssr"); + let fullyCachedElt = page.getByTestId("fullyCached"); + let isrElt = page.getByTestId("isr"); + await expect(fullyCachedElt).toBeVisible(); + await expect(isrElt).toBeVisible(); + + const initialFullyCachedText = await fullyCachedElt.textContent(); + const initialIsrText = await isrElt.textContent(); + + let isrText = initialIsrText; + + do { + await page.reload(); + fullyCachedElt = page.getByTestId("fullyCached"); + isrElt = page.getByTestId("isr"); + await expect(fullyCachedElt).toBeVisible(); + await expect(isrElt).toBeVisible(); + isrText = await isrElt.textContent(); + await page.waitForTimeout(1000); + } while (isrText === initialIsrText); + + expect(fullyCachedElt).toHaveText(initialFullyCachedText ?? ""); + expect(isrElt).not.toHaveText(initialIsrText ?? ""); +}); + +test("revalidateTag should work for fullyCached component", async ({ + page, + request, +}) => { + await page.goto("/use-cache/ssr"); + const fullyCachedElt = page.getByTestId("fullyCached"); + await expect(fullyCachedElt).toBeVisible(); + + const initialFullyCachedText = await fullyCachedElt.textContent(); + + const resp = await request.get("/api/revalidate"); + expect(resp.status()).toEqual(200); + expect(await resp.text()).toEqual("DONE"); + + await page.reload(); + await expect(fullyCachedElt).toBeVisible(); + expect(fullyCachedElt).not.toHaveText(initialFullyCachedText ?? ""); +}); From 4012f4f63517f7777e40035a71f0f704ffff5cf6 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Fri, 18 Apr 2025 15:09:30 +0200 Subject: [PATCH 13/14] lint --- examples/experimental/src/components/cached.tsx | 2 +- packages/tests-e2e/tests/experimental/use-cache.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/experimental/src/components/cached.tsx b/examples/experimental/src/components/cached.tsx index 34db53992..7abaa010c 100644 --- a/examples/experimental/src/components/cached.tsx +++ b/examples/experimental/src/components/cached.tsx @@ -1,4 +1,4 @@ -import { unstable_cacheTag, unstable_cacheLife } from "next/cache"; +import { unstable_cacheLife, unstable_cacheTag } from "next/cache"; export async function FullyCachedComponent() { "use cache"; diff --git a/packages/tests-e2e/tests/experimental/use-cache.test.ts b/packages/tests-e2e/tests/experimental/use-cache.test.ts index 1c750baf3..4847bdb28 100644 --- a/packages/tests-e2e/tests/experimental/use-cache.test.ts +++ b/packages/tests-e2e/tests/experimental/use-cache.test.ts @@ -1,4 +1,4 @@ -import { test, expect } from "@playwright/test"; +import { expect, test } from "@playwright/test"; test("cached component should work in ssr", async ({ page }) => { await page.goto("/use-cache/ssr"); From ae2d5d54ce8ed23b850ca778336a8a2b88777348 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Wed, 23 Apr 2025 10:26:41 +0200 Subject: [PATCH 14/14] patch use cache for ISR --- .../open-next/src/build/createServerBundle.ts | 2 + .../src/build/patch/patches/index.ts | 1 + .../build/patch/patches/patchFetchCacheISR.ts | 40 +++++++++++++++ .../tests/experimental/use-cache.test.ts | 49 +++++++++++++++++-- .../patch/patches/patchFetchCacheISR.test.ts | 48 ++++++++++++++++++ 5 files changed, 136 insertions(+), 4 deletions(-) diff --git a/packages/open-next/src/build/createServerBundle.ts b/packages/open-next/src/build/createServerBundle.ts index 997166ec8..3582f5549 100644 --- a/packages/open-next/src/build/createServerBundle.ts +++ b/packages/open-next/src/build/createServerBundle.ts @@ -28,6 +28,7 @@ import { patchFetchCacheSetMissingWaitUntil, patchNextServer, patchUnstableCacheForISR, + patchUseCacheForISR, } from "./patch/patches/index.js"; interface CodeCustomization { @@ -212,6 +213,7 @@ async function generateBundle( patchNextServer, patchEnvVars, patchBackgroundRevalidation, + patchUseCacheForISR, ...additionalCodePatches, ]); diff --git a/packages/open-next/src/build/patch/patches/index.ts b/packages/open-next/src/build/patch/patches/index.ts index 22ef817ba..bd46d6532 100644 --- a/packages/open-next/src/build/patch/patches/index.ts +++ b/packages/open-next/src/build/patch/patches/index.ts @@ -3,6 +3,7 @@ export { patchNextServer } from "./patchNextServer.js"; export { patchFetchCacheForISR, patchUnstableCacheForISR, + patchUseCacheForISR, } from "./patchFetchCacheISR.js"; export { patchFetchCacheSetMissingWaitUntil } from "./patchFetchCacheWaitUntil.js"; export { patchBackgroundRevalidation } from "./patchBackgroundRevalidation.js"; diff --git a/packages/open-next/src/build/patch/patches/patchFetchCacheISR.ts b/packages/open-next/src/build/patch/patches/patchFetchCacheISR.ts index 17ccea628..ca858c0fd 100644 --- a/packages/open-next/src/build/patch/patches/patchFetchCacheISR.ts +++ b/packages/open-next/src/build/patch/patches/patchFetchCacheISR.ts @@ -78,6 +78,29 @@ fix: ($STORE_OR_CACHE.isOnDemandRevalidate && !globalThis.__openNextAls?.getStore()?.isISRRevalidation) `; +export const useCacheRule = ` +rule: + kind: member_expression + pattern: $STORE_OR_CACHE.isOnDemandRevalidate + inside: + kind: binary_expression + has: + kind: member_expression + pattern: $STORE_OR_CACHE.isDraftMode + inside: + kind: if_statement + stopBy: end + has: + kind: return_statement + any: + - has: + kind: 'true' + - has: + regex: '!0' + stopBy: end +fix: + '($STORE_OR_CACHE.isOnDemandRevalidate && !globalThis.__openNextAls?.getStore()?.isISRRevalidation)'`; + export const patchFetchCacheForISR: CodePatcher = { name: "patch-fetch-cache-for-isr", patches: [ @@ -111,3 +134,20 @@ export const patchUnstableCacheForISR: CodePatcher = { }, ], }; + +export const patchUseCacheForISR: CodePatcher = { + name: "patch-use-cache-for-isr", + patches: [ + { + versions: ">=15.3.0", + field: { + pathFilter: getCrossPlatformPathRegex( + String.raw`(server/chunks/.*\.js|.*\.runtime\..*\.js|use-cache/use-cache-wrapper\.js)$`, + { escape: false }, + ), + contentFilter: /\.isOnDemandRevalidate/, + patchCode: createPatchCode(useCacheRule, Lang.JavaScript), + }, + }, + ], +}; diff --git a/packages/tests-e2e/tests/experimental/use-cache.test.ts b/packages/tests-e2e/tests/experimental/use-cache.test.ts index 4847bdb28..8f4111717 100644 --- a/packages/tests-e2e/tests/experimental/use-cache.test.ts +++ b/packages/tests-e2e/tests/experimental/use-cache.test.ts @@ -21,9 +21,8 @@ test("cached component should work in ssr", async ({ page }) => { isrText = await isrElt.textContent(); await page.waitForTimeout(1000); } while (isrText === initialIsrText); - - expect(fullyCachedElt).toHaveText(initialFullyCachedText ?? ""); - expect(isrElt).not.toHaveText(initialIsrText ?? ""); + const fullyCachedText = await fullyCachedElt.textContent(); + expect(fullyCachedText).toEqual(initialFullyCachedText); }); test("revalidateTag should work for fullyCached component", async ({ @@ -42,5 +41,47 @@ test("revalidateTag should work for fullyCached component", async ({ await page.reload(); await expect(fullyCachedElt).toBeVisible(); - expect(fullyCachedElt).not.toHaveText(initialFullyCachedText ?? ""); + const newFullyCachedText = await fullyCachedElt.textContent(); + expect(newFullyCachedText).not.toEqual(initialFullyCachedText); +}); + +test("cached component should work in isr", async ({ page }) => { + await page.goto("/use-cache/isr"); + + let fullyCachedElt = page.getByTestId("fullyCached"); + let isrElt = page.getByTestId("isr"); + + await expect(fullyCachedElt).toBeVisible(); + await expect(isrElt).toBeVisible(); + + let initialFullyCachedText = await fullyCachedElt.textContent(); + let initialIsrText = await isrElt.textContent(); + + // We have to force reload until ISR has triggered at least once, otherwise the test will be flakey + + let isrText = initialIsrText; + + while (isrText === initialIsrText) { + await page.reload(); + isrElt = page.getByTestId("isr"); + fullyCachedElt = page.getByTestId("fullyCached"); + await expect(isrElt).toBeVisible(); + isrText = await isrElt.textContent(); + await expect(fullyCachedElt).toBeVisible(); + initialFullyCachedText = await fullyCachedElt.textContent(); + await page.waitForTimeout(1000); + } + initialIsrText = isrText; + + do { + await page.reload(); + fullyCachedElt = page.getByTestId("fullyCached"); + isrElt = page.getByTestId("isr"); + await expect(fullyCachedElt).toBeVisible(); + await expect(isrElt).toBeVisible(); + isrText = await isrElt.textContent(); + await page.waitForTimeout(1000); + } while (isrText === initialIsrText); + const fullyCachedText = await fullyCachedElt.textContent(); + expect(fullyCachedText).toEqual(initialFullyCachedText); }); diff --git a/packages/tests-unit/tests/build/patch/patches/patchFetchCacheISR.test.ts b/packages/tests-unit/tests/build/patch/patches/patchFetchCacheISR.test.ts index 649c5cc13..e6d421aee 100644 --- a/packages/tests-unit/tests/build/patch/patches/patchFetchCacheISR.test.ts +++ b/packages/tests-unit/tests/build/patch/patches/patchFetchCacheISR.test.ts @@ -2,6 +2,7 @@ import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js"; import { fetchRule, unstable_cacheRule, + useCacheRule, } from "@opennextjs/aws/build/patch/patches/patchFetchCacheISR.js"; import { describe } from "vitest"; @@ -54,6 +55,24 @@ const patchFetchCacheCodeMinifiedNext15 = ` let t=P.isOnDemandRevalidate?null:await V.get(n,{kind:l.IncrementalCacheKind.FETCH,revalidate:_,fetchUrl:y,fetchIdx:X,tags:N,softTags:C}); `; +const patchUseCacheUnminified = ` +function shouldForceRevalidate(workStore, workUnitStore) { + if (workStore.isOnDemandRevalidate || workStore.isDraftMode) { + return true; + } + if (workStore.dev && workUnitStore) { + if (workUnitStore.type === 'request') { + return workUnitStore.headers.get('cache-control') === 'no-cache'; + } + if (workUnitStore.type === 'cache') { + return workUnitStore.forceRevalidate; + } + } + return false; +}`; +const patchUseCacheMinified = ` +function D(e,t){if(e.isOnDemandRevalidate||e.isDraftMode)return!0;if(e.dev&&t){if("request"===t.type)return"no-cache"===t.headers.get("cache-control");if("cache"===t.type)return t.forceRevalidate}return!1}`; + describe("patchUnstableCacheForISR", () => { test("on unminified code", async () => { expect( @@ -124,3 +143,32 @@ describe("patchFetchCacheISR", () => { }); //TODO: Add test for Next 14.2.24 }); + +describe("patchUseCache", () => { + test("on unminified code", async () => { + expect( + patchCode(patchUseCacheUnminified, useCacheRule), + ).toMatchInlineSnapshot(` +"function shouldForceRevalidate(workStore, workUnitStore) { + if ((workStore.isOnDemandRevalidate && !globalThis.__openNextAls?.getStore()?.isISRRevalidation) || workStore.isDraftMode) { + return true; + } + if (workStore.dev && workUnitStore) { + if (workUnitStore.type === 'request') { + return workUnitStore.headers.get('cache-control') === 'no-cache'; + } + if (workUnitStore.type === 'cache') { + return workUnitStore.forceRevalidate; + } + } + return false; +}"`); + }); + test("on minified code", async () => { + expect( + patchCode(patchUseCacheMinified, useCacheRule), + ).toMatchInlineSnapshot(` +"function D(e,t){if((e.isOnDemandRevalidate && !globalThis.__openNextAls?.getStore()?.isISRRevalidation)||e.isDraftMode)return!0;if(e.dev&&t){if("request"===t.type)return"no-cache"===t.headers.get("cache-control");if("cache"===t.type)return t.forceRevalidate}return!1}" +`); + }); +});