lagon icon indicating copy to clipboard operation
lagon copied to clipboard

Support Next.js

Open QuiiBz opened this issue 2 years ago • 6 comments

Support Next.js SSR with the new Edge Runtime.

  • [x] pages directory
  • [x] app directory with React Server Components & streaming
  • [ ] Integration in the CLI to bundle all the edge functions in a single one

QuiiBz avatar Jun 30 '22 19:06 QuiiBz

Update: both the pages directory and the app directory are working!

https://twitter.com/tomlienard/status/1613229200789438464

QuiiBz avatar Jan 11 '23 18:01 QuiiBz

Update: created #612 because Next.js now expects AsyncLocalStorage to be present in the global scope.

QuiiBz avatar Feb 23 '23 20:02 QuiiBz

Update: AsyncLocalStorage has been merged for a few weeks, but Next.js now expects the runtime to support imports (and specifically an implementation of Buffer from node:buffer), which we don’t have at all right now and would make the runtime even more complicated.

https://twitter.com/ascorbic/status/1648264283824742401?s=46&t=vptTziexWvl21M22w1Jv0w

QuiiBz avatar Apr 18 '23 10:04 QuiiBz

Any reason not leveraging unjs/unenv or nitro to bundle output?

pi0 avatar Jul 31 '23 15:07 pi0

Great question! Implementing these APIs (AsyncLocalStorage, Buffer...) should be done in the runtime itself because it needs to be very performant. They will ultimately be implemented natively (instead of in JS-land right now) so it doesn't really make sense to use unenv now and remove it later.

QuiiBz avatar Jul 31 '23 16:07 QuiiBz

Yes makes sense for ALS cannot be implemented in Userland. (unenv will also auto-detect such environments and use native soon. It only has a shim. But Buffer and other Node.js APIs used by next.js or user dependencies can possibly use can be leveraged unenv userland impl same as Nuxt.

pi0 avatar Aug 01 '23 09:08 pi0