Skip to content

Conversation

@conico974
Copy link
Contributor

Enhance the cache interceptor to support PPR by introducing new types and modifying the request handling logic. This allows for immediate response delivery while processing requests in the background. Additionally, improve logging for better debugging.

One thing that doesn't work right now, is with an external middleware, but it might make sense to do it later. Especially if we plan to make the StreamCreator mandatory. Right now it would require to do it at the converter level.

Only works with the Adapter API

@changeset-bot
Copy link

changeset-bot bot commented Dec 7, 2025

🦋 Changeset detected

Latest commit: a2e94ff

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

This PR includes changesets to release 2 packages
Name Type
@opennextjs/aws Minor
app-pages-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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/aws@1057

commit: a2e94ff

"@opennextjs/aws": minor
---

Make PPR work with the cache interceptor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to make it clear that it "Only works with the Adapter API" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however I am not sure to understand from the code why/where the logic is scoped to the adapter handler, could you expand on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's on the Next side, basically the resume endpoint is only available using the adapter (or in minimal mode or with some patch)

"generateResult called with unsupported cache value type, only 'app' and 'page' are supported",
);
}
// close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What to do with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it

if (isInternalResult(cacheInterceptionResult)) {
applyMiddlewareHeaders(cacheInterceptionResult, headers);
return cacheInterceptionResult;
} else if (isPartialResult(cacheInterceptionResult)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no else after return?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an else if, there is a third case that none of these 2 are supposed to catch (when it is an InternalEvent)

return eventOrResult;
const cacheInterceptionResult = await cacheInterceptor(eventOrResult);
if (isInternalResult(cacheInterceptionResult)) {
applyMiddlewareHeaders(cacheInterceptionResult, headers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: would it make sense for applyMiddlewareHeaders() to return the first param?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess. I'll have to check everywhere where it's used, but yeah

} else if (cachedValue.type === "page") {
isDataRequest = Boolean(event.query.__nextDataReq);
body = isDataRequest ? JSON.stringify(cachedValue.json) : cachedValue.html;
if (isDataRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to change the ternary to an if then it would make sense to fold l 232 here as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants