opennextjs / opennextjs-aws

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

Feat external cache #480

Closed conico974 closed 1 month ago

conico974 commented 2 months ago

This PR allow the ISR/SSG cache to resolve before reaching NextServer. This has 2 big benefits:

It is still WIP :

Some notes around PPR : We probably want next to settle on an implementation, because as of right now there is no way to do it outside of minimal mode. There is a dirty solution for this, we could have 2 version of NextServer running inside the handler, one in minimalMode for PPR and the normal one for the rest. Maybe they'll decide to allow this for anyone and not only on vercel. ( we just need to have acces to the _next/resume endpoints )

changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: 956ea50997bd7fcb1c5812793de3452da9283192

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages | Name | Type | | ---------------- | ----- | | open-next | Minor | | app-pages-router | Patch | | app-router | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
open-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 22, 2024 9:07am
conico974 commented 1 month ago

I think this one is done and should work in most cases. As for a proper PPR implementation, almost everything is in place but i think we really need to wait to see what they end up doing with the upstream implementation.

In previous implementation they provided the prerendered html at build time (it might still be the case in some occasion as the code is still there) and the only thing left to do to recreate the complete html was to create a stream, push the initial html into the stream, and then push the result of the _next/resume endpoint into it and it was done.

At the moment, it looks like they do not provide the prerendered html anymore and we have to reconstruct it. A dirty way that seemed to work was to just create a shell html like that and use it (It's very likely broken in a lot of cases)

<!DOCTYPE html><html>
  <head>
    <meta charSet="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
   <!-- Here we insert every these 2 necessary script for the page  -->
    <script src="http://localhost:3000/_next/static/chunks/webpack-6540e76769ad5f68.js" async=""></script>
    <script src="http://localhost:3000/_next/static/chunks/main-app-a079acdba6bedcac.js" async=""></script>
  </head>
  <body>

The proper way to do it would be to use the prerender function from react-dom/static.edge with all the correct next provider as children, but it means a lot of reverse engineering. But hopefully they'll just prerender the html once it is ready