-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: correct precedence when building urlToUse in createLocalReq #14901
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
This appears to be a new error produced with the latest update of next.
Occurs when front end is using a simple <Link> component for example <Link href="/admin"> to send a user to the payloadcms backend. This throws a new error.
```
[20:11:25] ERROR: Failed to create URL object from URL: http://localhost:3000http://localhost:3000/admin, falling back to http://localhost:3000http://localhost:3000/admin
⨯ TypeError: Invalid URL
at ignore-listed frames {
code: 'ERR_INVALID_URL',
input: 'http://localhost:3000http://localhost:3000/admin',
digest: '1079054744'
}
node_modules\.pnpm\@payloadcms+next@3.68.3_@ty_5c4107aa334225014c648de0038e6397\node_modules\@payloadcms\next\src\utilities\initReq.ts (103:25) @ <anonymous> 101 | const { req: reqOverrides, ...optionsOverrides } = overrides || {} 102 | > 103 | const req = await createLocalReq( | ^ 104 | { 105 | req: { 106 | headers,
```
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.
Pull request overview
This PR fixes a bug where Next.js Link components pointing to /admin caused URL duplication errors (e.g., http://localhost:3000http://localhost:3000/admin). The issue stemmed from faulty conditional logic in URL construction that would use serverURL even when req.url was already set.
Key changes:
- Refactored the URL construction logic to properly prioritize
req.urloverserverURL - Added trailing slash removal from
serverURLto prevent malformed URLs - Converted ternary expression to explicit if-else blocks for clearer URL selection logic
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Hey @rubixvi, this does prevent the admin panel itself from crashing, but I was able to produce the following url when navigating to the list view: Clearly this is wrong...we must not be relying on it anywhere else. This was definitely introduced in #14869, but the problem is related to the url suffix, not necessary how the url is constructed. As the name implies, the suffix shouldn't include the server url in the first place. Your fix passes because the incorrect suffix happens to start with a leading slash: This allows us to construct a valid url object, albeit with an incorrect path. The problem is that
I also imagine your change might cause other issues too, for example |
|
@jacobsfletch I'll start a patch file and come back to this, just realise /dashboard and root /admin are affected at the moment. I couldn't reproduce the error in list view. |
|
Got a fix queued up here: #14907 |
Fixes #14900. Supersedes #14901. Since #14869, loading the admin panel with a `serverURL` crashes with the following error: ``` ⨯ [TypeError: Invalid URL] { code: 'ERR_INVALID_URL', input: 'http://localhost:3000http://localhost:3000/admin', digest: '185251315' } [12:26:08] ERROR: Failed to create URL object from URL: http://localhost:3000http://localhost:3000/admin, falling back to http://localhost:3000http://localhost:3000/admin ``` This is because the suffix used to create a local req object was changed to include the server URL. As the name implies, it should be a relative path that appends onto the base URL.
This appears to be a new error produced with the latest update of next.
Occurs when front end is using a simple component for example to send a user to the payloadcms backend. This throws a new error. This only occurs with links to the /admin page.
Fixes #14900