Skip to content
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

fix: add AsyncLocalStorage to globalThis #1907

Merged
merged 10 commits into from
Feb 2, 2023
Merged

fix: add AsyncLocalStorage to globalThis #1907

merged 10 commits into from
Feb 2, 2023

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Jan 27, 2023

Summary

Since version 13.1.2, Next.js has required AsyncLocalStorage to be available on the global object for edge SSR. Deno, being excellent people, have now added an implementation to their node compat library, so this adds that to globalThis.

Test plan

  1. Load /app-edge in the default demo

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

Fixes #1851

Standard checks:

image

  • Check the Deploy Preview's Demo site for your PR's functionality
  • Add docs when necessary

🧪 Once merged, make sure to update the version if needed and that it was published correctly.

@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/63db9b8fbc73eb0008060a50
😎 Deploy Preview https://deploy-preview-1907--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/63db9b8f8d2ca6000848e551
😎 Deploy Preview https://deploy-preview-1907--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/63db9b8fdc82f80008577c84
😎 Deploy Preview https://deploy-preview-1907--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jan 27, 2023
@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/63db9b8f6704e60008ce3860
😎 Deploy Preview https://deploy-preview-1907--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/63db9b8f6fed1600077eaae8
😎 Deploy Preview https://deploy-preview-1907--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/63db9b8fca55b40009111a83
😎 Deploy Preview https://deploy-preview-1907--next-plugin-canary.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/63db9b8f8d2ca6000848e556
😎 Deploy Preview https://deploy-preview-1907--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/63db9b8fb92d630008d56fcd
😎 Deploy Preview https://deploy-preview-1907--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 1390051
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/63db9b8f3fdef60008c458cf
😎 Deploy Preview https://deploy-preview-1907--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@ascorbic ascorbic self-assigned this Jan 30, 2023
@ascorbic ascorbic mentioned this pull request Jan 30, 2023
2 tasks
@ascorbic ascorbic marked this pull request as ready for review February 1, 2023 08:50
@ascorbic ascorbic requested a review from a team February 1, 2023 08:50
Comment on lines -32 to +45
it(`${label}should fail when returning a stream`, async () => {
it(`${label}should not fail when returning a stream`, async () => {
const res = await fetchViaHTTP(next.url, `${locale}/stream-a-response`)
expect(res.status).toBe(500)
expect(res.status).toBe(200)

if (!(global as any).isNextDeploy) {
expect(await res.text()).toEqual('Internal Server Error')
expect(next.cliOutput).toContain(
expect(next.cliOutput).not.toContain(
`A middleware can not alter response's body. Learn more: https://nextjs.org/docs/messages/returning-response-body-in-middleware`
)
}
})

it(`${label}should fail when returning a text body`, async () => {
it(`${label}should not fail when returning a text body`, async () => {
const res = await fetchViaHTTP(next.url, `${locale}/send-response`)
expect(res.status).toBe(500)
expect(res.status).toBe(200)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are test changes from upstream

@nickytonline
Copy link

Also for more context, this is to mirror what they're doing in their repo.

// expose AsyncLocalStorage on globalThis for react usage
const { AsyncLocalStorage } = require('async_hooks')
;(globalThis as any).AsyncLocalStorage = AsyncLocalStorage

https://github.com/vercel/next.js/blob/77aa75c6c486118c2cf76013a664914eee2766b0/packages/next/src/export/worker.ts#LL107-L109C59

Copy link

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

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

Tested the demo page and it works as expected. :shipit:

CleanShot 2023-02-01 at 14 55 54

@@ -0,0 +1,11 @@
'use client'

// TODO-APP: support typing for useSelectedLayoutSegment

Choose a reason for hiding this comment

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

Is there an issue for 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.

This is a Next.js demo site, not our code


// TODO-APP: support typing for useSelectedLayoutSegment
// @ts-ignore
import { useSelectedLayoutSegments } from 'next/navigation'

Choose a reason for hiding this comment

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

Copy link

@sarahetter sarahetter left a comment

Choose a reason for hiding this comment

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

LGTM!

@ascorbic ascorbic merged commit 1ec8203 into main Feb 2, 2023
@ascorbic ascorbic deleted the mk/als-test branch February 2, 2023 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add AsyncLocalStorage to edge runtime
3 participants