Skip to content

Conversation

@LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Jul 3, 2024

Description

Fixes #3660

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@LauraBeatris LauraBeatris self-assigned this Jul 3, 2024
@changeset-bot
Copy link

changeset-bot bot commented Jul 3, 2024

🦋 Changeset detected

Latest commit: 00b7447

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

This PR includes changesets to release 1 package
Name Type
@clerk/nextjs 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

@LauraBeatris LauraBeatris changed the title fix(nextjs): Use AsyncLocalStorage as global for edge runtime fix(nextjs): Use AsyncLocalStorage as global for edge runtime Jul 3, 2024
@LauraBeatris LauraBeatris marked this pull request as ready for review July 3, 2024 20:52
@LauraBeatris LauraBeatris changed the title fix(nextjs): Use AsyncLocalStorage as global for edge runtime fix(nextjs): Use AsyncLocalStorage for edge runtime Jul 3, 2024
@LauraBeatris LauraBeatris changed the title fix(nextjs): Use AsyncLocalStorage for edge runtime fix(nextjs): Update imports to avoid Node.js build warnings on edge runtime Jul 4, 2024
@LauraBeatris LauraBeatris marked this pull request as draft July 4, 2024 00:26
@LauraBeatris LauraBeatris marked this pull request as ready for review July 4, 2024 13:24
import { logger } from '@clerk/shared';
import { handleValueOrFn } from '@clerk/shared/handleValueOrFn';
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
import { logger } from '@clerk/shared/logger';
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes the build warnings where MessageEvent was being imported during the edge runtime, since it was being resolved on the root of @clerk/shared.

@@ -1,3 +1,5 @@
import { AsyncLocalStorage } from 'node:async_hooks';
Copy link
Member Author

Choose a reason for hiding this comment

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

By using node:async_hooks, it uses the AsyncLocalStorage polyfill from Next.js. TBH it's a controversy from what Vercel docs mention, in which async_hooks would also be polyfilled: https://vercel.com/docs/functions/runtimes/edge-runtime#compatible-node.js-modules

CleanShot 2024-07-04 at 10 26 57

@LauraBeatris LauraBeatris merged commit e8a2af5 into main Jul 4, 2024
@LauraBeatris LauraBeatris deleted the fix/use-als-global branch July 4, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@clerk/[email protected] cause a build warning in NextJS middleware

4 participants