lagonapp / lagon

Deploy Serverless Functions at the Edge. Current status: Alpha
https://lagon.app
GNU Affero General Public License v3.0
1.32k stars 62 forks source link

Support Next.js #47

Open QuiiBz opened 2 years ago

QuiiBz commented 2 years ago

Support Next.js SSR with the new Edge Runtime.

QuiiBz commented 1 year ago

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

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

QuiiBz commented 1 year ago

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

QuiiBz commented 1 year ago

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

pi0 commented 1 year ago

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

QuiiBz commented 1 year ago

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.

pi0 commented 1 year ago

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.