opennextjs / opennextjs-aws

Open-source Next.js adapter for AWS
https://open-next.js.org
MIT License
3.9k stars 119 forks source link

Next.js 15 (after 15.0.0-canary.13) support #507

Closed braska closed 6 days ago

braska commented 2 weeks ago

[!NOTE] Disclaimer: although I recognize it might be too early to think about Next.js 15 support, but it might be beneficial. I suggest at least to consider it.

Although OpenNext works fine with next@rc, it doesn't work with latest Next.js 15 canary (which eventually be a new RC). Issue is related to incremenatal cache changes. Specifically: kind values before were FETCH, IMAGE, REDIRECT, ROUTE, PAGE, but now values are FETCH, IMAGE, REDIRECT, APP_PAGE, APP_ROUTE, PAGES.

Next.js 14.2.8 implementation: https://github.com/vercel/next.js/blob/v14.2.8/packages/next/src/server/response-cache/types.ts#L92-L97 Next.js 15.0.0-rc.0 implementation (same as 14.2.8): https://github.com/vercel/next.js/blob/v15.0.0-rc.0/packages/next/src/server/response-cache/types.ts#L92-L97 Next.js 15.0.0-canary.145 implementation: https://github.com/vercel/next.js/blob/v15.0.0-canary.145/packages/next/src/server/response-cache/types.ts#L141-L147

Note: new APP_PAGE kind also has different object structure: https://github.com/vercel/next.js/blob/v15.0.0-canary.145/packages/next/src/server/response-cache/types.ts#L110-L119

I tracked down these changes to this commit: https://github.com/vercel/next.js/commit/e456acd85462bcf1807f6662f21ee16cedb2409d. It was released in 15.0.0-canary.13.

My understanding is that changes should be done here: https://github.com/sst/open-next/blob/main/packages/open-next/src/adapters/cache.ts

I confirmed that latest OpenNext (3.1.1) doesn't work with Next.js 15.0.0-canary.145. While it can be successfully deployed, when you try to open deployed application server function will fail with the following stack trace:

⨯ TypeError: result.toUnchunkedString is not a function
    at sendRenderResult (/var/task/node_modules/.pnpm/next@15.0.0-canary.145_@opentelemetry+api@1.9.0_react-dom@19.0.0-rc-a03254bc-20240905_react@1_675uctallwwvzvgc2kh2q6726i/node_modules/next/dist/server/send-payload.js:64:54)
    at NextNodeServer.sendRenderResult (/var/task/node_modules/.pnpm/next@15.0.0-canary.145_@opentelemetry+api@1.9.0_react-dom@19.0.0-rc-a03254bc-20240905_react@1_675uctallwwvzvgc2kh2q6726i/node_modules/next/dist/server/next-server.js:573:50)
    at NextNodeServer.pipeImpl (/var/task/node_modules/.pnpm/next@15.0.0-canary.145_@opentelemetry+api@1.9.0_react-dom@19.0.0-rc-a03254bc-20240905_react@1_675uctallwwvzvgc2kh2q6726i/node_modules/next/dist/server/base-server.js:972:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async NextNodeServer.handleCatchallRenderRequest (/var/task/node_modules/.pnpm/next@15.0.0-canary.145_@opentelemetry+api@1.9.0_react-dom@19.0.0-rc-a03254bc-20240905_react@1_675uctallwwvzvgc2kh2q6726i/node_modules/next/dist/server/next-server.js:283:17)
    at async NextNodeServer.runImpl (/var/task/node_modules/.pnpm/next@15.0.0-canary.145_@opentelemetry+api@1.9.0_react-dom@19.0.0-rc-a03254bc-20240905_react@1_675uctallwwvzvgc2kh2q6726i/node_modules/next/dist/server/base-server.js:942:9)
    at async NextNodeServer.handleRequestImpl (/var/task/node_modules/.pnpm/next@15.0.0-canary.145_@opentelemetry+api@1.9.0_react-dom@19.0.0-rc-a03254bc-20240905_react@1_675uctallwwvzvgc2kh2q6726i/node_modules/next/dist/server/base-server.js:876:20)
    at async jX (file:///var/task/modules/frontend/index.mjs:58:239839)
    at async file:///var/task/modules/frontend/index.mjs:58:239536
    at async Wk (file:///var/task/modules/frontend/index.mjs:58:239430)
conico974 commented 2 weeks ago

Yeah we can add support for this, we already fixed an issue with the middleware that only affected next 15 https://github.com/sst/open-next/pull/473