Skip to content

Breadcrumbs not working when using DefaultTemplate with a CustomRootView #12344

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

Closed
mikecebul opened this issue May 8, 2025 · 5 comments
Closed

Comments

@mikecebul
Copy link
Contributor

mikecebul commented May 8, 2025

Describe the Bug

When using a CustomRootView I want to use the DefaultTemplate, but the breadcrumbs in the navbar isn't working to navigate back to home (to "/admin"). Looking at the source code it appears stepNav.length < 1 resulting in it rendering a <div /> instead of an <a />.

Plus when you navigate to any page in the admin panel like "/admin/pages" and back to "/admin/custom-default" the breadcrumbs component does not update without a browser refresh.

Link to the code that reproduces this issue

create-payload-app --example custom-components

Reproduction Steps

  1. Run the custom-components example
  2. Navigate to "admin/custom-default"
  3. Try to navigate back to the dashboard using the icon in the breadcrumbs
custom-view-issue.mov

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
  Node: 20.18.2
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: 10.10.0
Relevant Packages:
  payload: 3.37.0
  next: 15.3.2
  @payloadcms/db-mongodb: 3.37.0
  @payloadcms/graphql: 3.37.0
  @payloadcms/next/utilities: 3.37.0
  @payloadcms/richtext-lexical: 3.37.0
  @payloadcms/translations: 3.37.0
  @payloadcms/ui/shared: 3.37.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
@mikecebul mikecebul added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction Auto-added tag on create to tell bot to check recreation URL, removed after check. labels May 8, 2025
@github-actions github-actions bot added created-by: Contributor and removed validate-reproduction Auto-added tag on create to tell bot to check recreation URL, removed after check. labels May 8, 2025
Copy link
Contributor

github-actions bot commented May 8, 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-reproduction label?

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 blank or 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

@mikecebul
Copy link
Contributor Author

I tried setting the steps manually with:

export const CustomDefaultRootView: React.FC<AdminViewServerProps> = ({
  initPageResult,
  params,
  searchParams,
}) => {
  const nav = [
    { label: "Dashboard", url: "/admin" },
    { label: "Custom Default View", url: "/admin/custom-default" },
  ];
  return (
    <StepNavProvider>
      <DefaultTemplate
        i18n={initPageResult.req.i18n}
        locale={initPageResult.locale}
        params={params}
        payload={initPageResult.req.payload}
        permissions={initPageResult.permissions}
        searchParams={searchParams}
        user={initPageResult.req.user || undefined}
        visibleEntities={initPageResult.visibleEntities}
      >
        <SetStepNav nav={nav} />
        <Gutter>
          <h1>Custom Default Root View</h1>
          <br />
          <p>This view uses the Default Template.</p>
          <CheckSteps />
        </Gutter>
      </DefaultTemplate>
    </StepNavProvider>
  );
};

but the steps are still an empty []

@mikecebul
Copy link
Contributor Author

Here is my decent enough workaround until this gets resolved.

'use client'

import { HomeIcon } from 'lucide-react'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import React from 'react'

export default function Icon() {
  const pathname = usePathname()
  const icon = <HomeIcon size={17} className="text-primary" />

  if (pathname === '/admin/analytics') {
    return <Link href="/admin">{icon}</Link>
  }

  return icon
}

@mikecebul
Copy link
Contributor Author

I was supposed to use the <SetStepNav />

import type { AdminViewServerProps } from 'payload'

import { DefaultTemplate } from '@payloadcms/next/templates'
import { Gutter, SetStepNav } from '@payloadcms/ui'

const AnalyticsDefaultRootView: React.FC<AdminViewServerProps> = ({
  initPageResult,
  params,
  searchParams,
}) => {
  const navItem = [
    {
      label: 'Analytics',
      url: '/analytics',
    },
  ]
  return (
    <DefaultTemplate
      i18n={initPageResult.req.i18n}
      locale={initPageResult.locale}
      params={params}
      payload={initPageResult.req.payload}
      permissions={initPageResult.permissions}
      searchParams={searchParams}
      user={initPageResult.req.user || undefined}
      visibleEntities={initPageResult.visibleEntities}
    >
      <SetStepNav nav={navItem} />  // This sets the bread crumbs
      <Gutter>
        <iframe
          src="https://analytics.mikecebul.dev/share/<key>/basesmi.org"
          width="100%"
          height="100%"
          style={{ border: 'none', overflow: 'hidden', minHeight: '85dvh' }}
          title="Analytics"
          allowFullScreen
          loading="lazy"
        />
      </Gutter>
    </DefaultTemplate>
  )
}

export default AnalyticsDefaultRootView

@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label May 9, 2025
Copy link
Contributor

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant