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(remix): RequestInit.duplex now is required if body is provided in undici #3495

Conversation

octoper
Copy link
Member

@octoper octoper commented Jun 3, 2024

Description

RequestInit.duplex now is required if body is provided:

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:

Copy link

changeset-bot bot commented Jun 3, 2024

🦋 Changeset detected

Latest commit: f6fb0eb

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

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

@octoper octoper changed the title fix: fix: RequestInit.duplex now is required if body is provided in Unidici Jun 3, 2024
@octoper octoper changed the title fix: RequestInit.duplex now is required if body is provided in Unidici fix: RequestInit.duplex now is required if body is provided in undici Jun 3, 2024
@octoper octoper self-assigned this Jun 3, 2024
@octoper
Copy link
Member Author

octoper commented Jun 3, 2024

!snapshot

@octoper octoper changed the title fix: RequestInit.duplex now is required if body is provided in undici fix(backend): RequestInit.duplex now is required if body is provided in undici Jun 3, 2024
@clerk-cookie
Copy link
Collaborator

Hey @octoper - the snapshot version command generated the following package versions:

Package Version
@clerk/backend 1.2.2-snapshot.v72984d5
@clerk/chrome-extension 1.0.17-snapshot.v72984d5
@clerk/clerk-js 5.6.0-snapshot.v72984d5
@clerk/elements 0.6.0-snapshot.v72984d5
@clerk/clerk-expo 1.1.9-snapshot.v72984d5
@clerk/express 0.0.11-snapshot.v72984d5
@clerk/fastify 1.0.13-snapshot.v72984d5
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/localizations 2.4.4-snapshot.v72984d5
@clerk/nextjs 5.1.4-snapshot.v72984d5
@clerk/clerk-react 5.2.3-snapshot.v72984d5
@clerk/remix 4.0.14-snapshot.v72984d5
@clerk/clerk-sdk-node 5.0.10-snapshot.v72984d5
@clerk/shared 2.2.2-snapshot.v72984d5
@clerk/testing 1.1.6-snapshot.v72984d5
@clerk/themes 2.1.9-snapshot.v72984d5
@clerk/types 4.6.0-snapshot.v72984d5

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/backend

npm i @clerk/backend@1.2.2-snapshot.v72984d5 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.0.17-snapshot.v72984d5 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.6.0-snapshot.v72984d5 --save-exact

@clerk/elements

npm i @clerk/elements@0.6.0-snapshot.v72984d5 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.1.9-snapshot.v72984d5 --save-exact

@clerk/express

npm i @clerk/express@0.0.11-snapshot.v72984d5 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.13-snapshot.v72984d5 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.4.4-snapshot.v72984d5 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.1.4-snapshot.v72984d5 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.2.3-snapshot.v72984d5 --save-exact

@clerk/remix

npm i @clerk/remix@4.0.14-snapshot.v72984d5 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.10-snapshot.v72984d5 --save-exact

@clerk/shared

npm i @clerk/shared@2.2.2-snapshot.v72984d5 --save-exact

@clerk/testing

npm i @clerk/testing@1.1.6-snapshot.v72984d5 --save-exact

@clerk/themes

npm i @clerk/themes@2.1.9-snapshot.v72984d5 --save-exact

@clerk/types

npm i @clerk/types@4.6.0-snapshot.v72984d5 --save-exact

@clerk-cookie clerk-cookie added remix and removed backend labels Jun 3, 2024
@octoper
Copy link
Member Author

octoper commented Jun 3, 2024

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @octoper - the snapshot version command generated the following package versions:

Package Version
@clerk/backend 1.2.2-snapshot.vef44e76
@clerk/chrome-extension 1.0.17-snapshot.vef44e76
@clerk/clerk-js 5.6.0-snapshot.vef44e76
@clerk/elements 0.6.0-snapshot.vef44e76
@clerk/clerk-expo 1.1.9-snapshot.vef44e76
@clerk/express 0.0.11-snapshot.vef44e76
@clerk/fastify 1.0.13-snapshot.vef44e76
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/localizations 2.4.4-snapshot.vef44e76
@clerk/nextjs 5.1.4-snapshot.vef44e76
@clerk/clerk-react 5.2.3-snapshot.vef44e76
@clerk/remix 4.0.14-snapshot.vef44e76
@clerk/clerk-sdk-node 5.0.10-snapshot.vef44e76
@clerk/shared 2.2.2-snapshot.vef44e76
@clerk/testing 1.1.6-snapshot.vef44e76
@clerk/themes 2.1.9-snapshot.vef44e76
@clerk/types 4.6.0-snapshot.vef44e76

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/backend

npm i @clerk/backend@1.2.2-snapshot.vef44e76 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.0.17-snapshot.vef44e76 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.6.0-snapshot.vef44e76 --save-exact

@clerk/elements

npm i @clerk/elements@0.6.0-snapshot.vef44e76 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.1.9-snapshot.vef44e76 --save-exact

@clerk/express

npm i @clerk/express@0.0.11-snapshot.vef44e76 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.13-snapshot.vef44e76 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.4.4-snapshot.vef44e76 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.1.4-snapshot.vef44e76 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.2.3-snapshot.vef44e76 --save-exact

@clerk/remix

npm i @clerk/remix@4.0.14-snapshot.vef44e76 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.10-snapshot.vef44e76 --save-exact

@clerk/shared

npm i @clerk/shared@2.2.2-snapshot.vef44e76 --save-exact

@clerk/testing

npm i @clerk/testing@1.1.6-snapshot.vef44e76 --save-exact

@clerk/themes

npm i @clerk/themes@2.1.9-snapshot.vef44e76 --save-exact

@clerk/types

npm i @clerk/types@4.6.0-snapshot.vef44e76 --save-exact

@octoper
Copy link
Member Author

octoper commented Jun 3, 2024

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @octoper - the snapshot version command generated the following package versions:

Package Version
@clerk/backend 1.2.2-snapshot.vff20ad3
@clerk/chrome-extension 1.0.17-snapshot.vff20ad3
@clerk/clerk-js 5.6.0-snapshot.vff20ad3
@clerk/elements 0.6.0-snapshot.vff20ad3
@clerk/clerk-expo 1.1.9-snapshot.vff20ad3
@clerk/express 0.0.11-snapshot.vff20ad3
@clerk/fastify 1.0.13-snapshot.vff20ad3
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/localizations 2.4.4-snapshot.vff20ad3
@clerk/nextjs 5.1.4-snapshot.vff20ad3
@clerk/clerk-react 5.2.3-snapshot.vff20ad3
@clerk/remix 4.0.14-snapshot.vff20ad3
@clerk/clerk-sdk-node 5.0.10-snapshot.vff20ad3
@clerk/shared 2.2.2-snapshot.vff20ad3
@clerk/testing 1.1.6-snapshot.vff20ad3
@clerk/themes 2.1.9-snapshot.vff20ad3
@clerk/types 4.6.0-snapshot.vff20ad3

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/backend

npm i @clerk/backend@1.2.2-snapshot.vff20ad3 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.0.17-snapshot.vff20ad3 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.6.0-snapshot.vff20ad3 --save-exact

@clerk/elements

npm i @clerk/elements@0.6.0-snapshot.vff20ad3 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.1.9-snapshot.vff20ad3 --save-exact

@clerk/express

npm i @clerk/express@0.0.11-snapshot.vff20ad3 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.13-snapshot.vff20ad3 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.4.4-snapshot.vff20ad3 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.1.4-snapshot.vff20ad3 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.2.3-snapshot.vff20ad3 --save-exact

@clerk/remix

npm i @clerk/remix@4.0.14-snapshot.vff20ad3 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.10-snapshot.vff20ad3 --save-exact

@clerk/shared

npm i @clerk/shared@2.2.2-snapshot.vff20ad3 --save-exact

@clerk/testing

npm i @clerk/testing@1.1.6-snapshot.vff20ad3 --save-exact

@clerk/themes

npm i @clerk/themes@2.1.9-snapshot.vff20ad3 --save-exact

@clerk/types

npm i @clerk/types@4.6.0-snapshot.vff20ad3 --save-exact

@octoper octoper force-pushed the vaggelis/sdk-1780-clerkremix-v4012-requestinit-duplex-option-is-required-when branch from ff20ad3 to 19e95a6 Compare June 10, 2024 14:43
@octoper octoper changed the title fix(backend): RequestInit.duplex now is required if body is provided in undici fix(remix): RequestInit.duplex now is required if body is provided in undici Jun 12, 2024
@octoper octoper force-pushed the vaggelis/sdk-1780-clerkremix-v4012-requestinit-duplex-option-is-required-when branch from 4895e8f to a238328 Compare June 12, 2024 11:22
@octoper octoper marked this pull request as ready for review June 12, 2024 13:18
@octoper octoper force-pushed the vaggelis/sdk-1780-clerkremix-v4012-requestinit-duplex-option-is-required-when branch 2 times, most recently from 4b53af7 to 58ca606 Compare June 12, 2024 16:31
Copy link
Member

@anagstef anagstef left a comment

Choose a reason for hiding this comment

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

💯

@octoper octoper force-pushed the vaggelis/sdk-1780-clerkremix-v4012-requestinit-duplex-option-is-required-when branch from 9db8246 to 4d7a407 Compare June 13, 2024 14:12
@anagstef anagstef merged commit 7ec5b1c into main Jun 14, 2024
15 checks passed
@anagstef anagstef deleted the vaggelis/sdk-1780-clerkremix-v4012-requestinit-duplex-option-is-required-when branch June 14, 2024 14:33
@ariofrio
Copy link

ariofrio commented Jul 18, 2024

I'm getting the following error:

Error: cannot clone body after it is used
    at clone (.../build/server.js:36692:15)
    at new Request2 (.../build/server.js:37302:99)
    at new NodeRequest (.../build/server.js:37754:9)
    at NodeRequest.clone (.../build/server.js:37760:16)
    at patchRequest (.../node_modules/@clerk/remix/src/ssr/utils.ts:128:33)
    at loadOptions (.../node_modules/@clerk/remix/src/ssr/loadOptions.ts:15:43)
    at Object.getAuth2 (.../node_modules/@clerk/remix/src/ssr/getAuth.ts:15:25)

The problem is that my code looks like this:

export async function action(args: ActionArgs) {
  const formData = await args.request.formData();
  const auth = await getAuth(args);
  ...
}

In other words, the request body is read before calling clerk.getAuth. Since Clerk attempts to clone the request, this causes an error. Is it necessary to clone the request to work around this duplex issue?

The workaround is to always call getAuth first:

export async function action(args: ActionArgs) {
  const auth = await getAuth(args);
  const formData = await args.request.formData();
  ...
}

But this is error-prone and easy to forget to do or accidentally change in a large project. At the minimum, this should be documented in the Clerk Remix guide. Ideally, this limitation would be removed.

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.

4 participants