Skip to content

fix(next): skip custom views without path prop in getCustomViewByRoute #13133

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jakenorthey
Copy link

@jakenorthey jakenorthey commented Jul 10, 2025

When using the @payloadcms/plugin-otp plugin, when the plugin redirects to the OTP screen, it reads the admin custom views config. If any views exist without the path property defined, the call to getCustomViewByRoute will fail with the error below:

TypeError: Cannot read properties of undefined (reading 'length')
    at <anonymous> (getCustomViewByRoute.ts:32:28)
    at getCustomViewByRoute (getCustomViewByRoute.ts:31:29)
    at getRouteData (getRouteData.ts:347:20)
    at RootPage (index.tsx:75:7)

This fix skips any custom views that do not have path defined.


@DanRibbens DanRibbens requested a review from jacobsfletch July 11, 2025 13:24
@jacobsfletch
Copy link
Member

This fix skips any custom views that do not have path defined.

This doesn't seem right. The path property should be required on all non-default root views. If you set up a custom view, it is expected that you'd provide a path for that view to mount to.

This feels more like a types issue than anything. The reason it's not required across the board is probably because we allow partial overrides of default views, like dashboard, etc. which provide their own path. To me it feels like we should require path on all non-default views.

If you're building a custom dashboard view, for example, you should be able to swap out only a portion of the config (omit the path):

{
  // ...
  admin: {
    // ...
    components: {
      // ...
      views: {
        dashboard: {
          Component: '/MyCustomDashboard'
        }
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants