Repository navigation
Description
Describe the Bug
b82356b updates all calls to formatAdminURL() to pass in config.serverURL. When I set serverURL: "http://localhost:3000", run npm run dev and go to http://localhost:3000/admin, I get the 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
It seems the function formatAdminURL() is also being used to get the path of routes, not just the absolute URL, so the commit breaks all of those cases if serverURL is set:
payload/packages/next/src/views/Root/index.tsx
Lines 66 to 70 in b82356b
| const currentRoute = formatAdminURL({ | |
| adminRoute, | |
| path: Array.isArray(params.segments) ? `/${params.segments.join('/')}` : null, | |
| serverURL: config.serverURL, | |
| }) |
Here, currentRoute is supposed to be the admin route, e.g., "/admin", but by passing in a set serverURL, it is now "http://localhost:3000/admin". Later on, in the same component:
payload/packages/next/src/views/Root/index.tsx
Lines 133 to 141 in b82356b
| overrides: { | |
| fallbackLocale: false, | |
| req: { | |
| query: qs.parse(queryString, { | |
| depth: 10, | |
| ignoreQueryPrefix: true, | |
| }), | |
| }, | |
| urlSuffix: `${currentRoute}${searchParams ? queryString : ''}`, |
urlSuffix is now "http://localhost:3000/admin", and this breaks createLocalReq(), which basically tries to construct the URL `http://localhost:3000http://localhost:3000/admin"
payload/packages/payload/src/utilities/createLocalReq.ts
Lines 41 to 44 in b82356b
| const urlToUse = | |
| req?.url || req.payload?.config?.serverURL | |
| ? `${req.payload?.config.serverURL}${urlSuffix || ''}` | |
| : fallbackURL |
Link to the code that reproduces this issue
N/A
Reproduction Steps
- Run
npx create-payload-app@latest -t blankwith SQLite driver - Set
serverURL: "http://localhost:3000",inpayload.config.ts - Run
npm run dev - Go to http://localhost:3000/admin
Which area(s) are affected?
area: core
Environment Info
Relevant Packages:
payload: 3.68.3
next: 15.5.9
@payloadcms/db-postgres: 3.68.3
@payloadcms/drizzle: 3.68.3
@payloadcms/graphql: 3.68.3
@payloadcms/next/utilities: 3.68.3
@payloadcms/plugin-cloud-storage: 3.68.3
@payloadcms/storage-s3: 3.68.3
@payloadcms/translations: 3.68.3
@payloadcms/ui/shared: 3.68.3
react: 19.2.1
react-dom: 19.2.1
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Activity
github-actions commentedon Dec 12, 2025
Please add a reproduction in order for us to be able to investigate.
Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.
Why was this issue marked with the
invalid-reproductionlabel?To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with
create-payload-app@latest -t blankor a forked/branched version of this repository with tests added (more info in the reproduction-guide).To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.
Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.
I added a link, why was it still marked?
Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.
Useful Resources
geminigeek commentedon Dec 13, 2025
same issue, remove serverURL it works
fix(next): properly construct local req url (#14907)
github-actions commentedon Dec 14, 2025
🚀 This is included in version v3.68.4
hai-trung-le commentedon Dec 15, 2025
It is still broken on v3.68.4, now going to
http://localhost:3000/admin/loginlead to an infinite redirect loop to itself.payload/packages/next/src/views/Root/index.tsx
Lines 150 to 154 in bb29c49
The Root component checks if the route is a public admin route to redirect if not, but
currentRouteis now an absolute URL, which breaksisPublicAdminRoute(), which assumes a relative route.I feel we should revert b82356b and redo it in a more systematic way, because
formatAdminURL()is doing three tasks at once: getting the absolute URL, getting the root relative URL (relative to origin), and getting the local relative URL (relative to base URL). Conflating them into one function is just inherently buggy.jtimi-mtbk commentedon Dec 15, 2025
@hai-trung-le correct
I still reproduce issue at: #14918
@denolfe please help us check it.
DanRibbens commentedon Dec 15, 2025
@jtimi-mtbk it is currently Sunday 11 PM for most of the team. We will fix and release another patch tomorrow.
I'm really sorry this has been an issue for everyone. I've proposed a way forward for the team to address in the morning.
github-actions commentedon Dec 15, 2025
🚀 This is included in version v3.68.5
jtimi-mtbk commentedon Dec 16, 2025
@DanRibbens Thank you to the team for the quick fix. I really appreciate everyone's effort. 🎉
github-actions commentedon Dec 23, 2025
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.
fix(next): properly construct local req url (#14907)
fix(next): omit server url from route matching (#14919)
fix(next): properly construct local req url (payloadcms#14907)
fix(next): omit server url from route matching (payloadcms#14919)