Skip to content

PayloadCMS 3.68.3 breaks admin UI when serverURL is set #14900

@hai-trung-le

Description

@hai-trung-le

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:

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:

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"

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 blank with SQLite driver
  • Set serverURL: "http://localhost:3000", in payload.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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions