-
Notifications
You must be signed in to change notification settings - Fork 159
next/after support and better AsyncLocalStorage context in general #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 18457d7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
A couple nits.
oh jeez that's a lot of lint warnings lol |
f2054c7
to
1c8aab6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are still a few instances of __als
in the tests
Ho right i missed them, should be good now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Would it make sense to add an e2e test for the next/after stuff?
@khuezy Yeah it would make sense, but i haven't figured out a way with our current setup. |
To truly test |
Ho this give me an idea, we create 2 endpoint one that got the after and another one that would be ssg. This is a bit hacky, but that's the only thing i can think of right now. |
Great idea, I don't think we'd need 2 endpoints for this. It can just be
The test would reload the page and check that the time hasn't changed until after 5 seconds... |
294aaca
to
14c5be3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,
only a few very minor things
console.log("date", date); | ||
return NextResponse.json({ date: date }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit
console.log("date", date); | |
return NextResponse.json({ date: date }); | |
console.log({ date }); | |
return NextResponse.json({ date }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i'll remove the console.log
entirely, not really useful
"@opennextjs/aws": patch | ||
--- | ||
|
||
add support for next/after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add
It can also be used to emulate vercel request context (the waitUntil) for lib that may rely on it on serverless env. It needs this env variable EMULATE_VERCEL_REQUEST_CONTEXT to be set to be enabled
|
||
const openNextStoreContext = globalThis.__openNextAls.getStore(); | ||
|
||
const awaiter = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename this to waitUntil
and change below get: () => ({ waitUntil })
- I feel like introducing a new name is not worth
This PR make the AsyncLocalStorage available to the middleware as well as the edge function.
It also provide support for
next/after
everytime including for lambda. On lambda without streaming it will block the response until all after promise are either resolved or rejected. Tested on lambda with streaming, it works as expected.It can also be used to emulate vercel request context (the waitUntil) for lib that may rely on it on serverless env. It needs this env variable
EMULATE_VERCEL_REQUEST_CONTEXT
to be set to be enabledAnd for wrapper that has native support for
waitUntil
they can provideglobalThis.openNextWaitUntil
( Should work on cloudflare, not tested though)I haven't found a way to test this with our current e2e setup, if someone has an idea ?