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

Response from patched fetch has undefined url property #51642

Closed
1 task done
adamjmcgrath opened this issue Jun 22, 2023 · 1 comment · Fixed by #51665
Closed
1 task done

Response from patched fetch has undefined url property #51642

adamjmcgrath opened this issue Jun 22, 2023 · 1 comment · Fixed by #51665
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked

Comments

@adamjmcgrath
Copy link
Contributor

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:53:19 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6020
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: 8.6.0
    Relevant packages:
      next: 13.4.7
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue or a replay of the bug

adamjmcgrath/next-res-url@6e7c9e8

To Reproduce

  • npm run dev
  • Visit localhost:3000
  • Observe the logs in the console:
res.url with defaults: 
res.url with "no-store": https://dog.ceo/api/breeds/list/all

Describe the Bug

When you make a fetch from an app directory page, the response does not have a URL property.

This causes libraries like oauth4webapi, to throw Invalid URL errors when they process fetch responses.

If you force the fetch not to cache, using cache: no-store the response has a URL - so it's probably an issue with https://github.com/vercel/next.js/blob/v13.4.7/packages/next/src/server/lib/patch-fetch.ts

Expected Behavior

The response from fetch should always have a url property equal to the final URL obtained after any redirects. https://developer.mozilla.org/en-US/docs/Web/API/Response/url

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Only tested in development mode

@adamjmcgrath adamjmcgrath added the bug Issue was opened via the bug report template. label Jun 22, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label Jun 22, 2023
@kodiakhq kodiakhq bot closed this as completed in #51665 Jun 23, 2023
kodiakhq bot pushed a commit that referenced this issue Jun 23, 2023
### What?

Add `url` property to response returned from patched fetch

### Why?

So that libraries that rely on `response.url` work with the app directory and fetch cacheing

### How?

Using the same code as https://github.com/vercel/edge-runtime/blob/edge-runtime%402.4.3/packages/primitives/src/primitives/fetch.js#L164

fixes #51642 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant