-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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