backstage: πŸ› Backstage HeaderTabs with v1.26.0 cause breaking changes

πŸ“œ Description

I can see that Backstage has introduced tabs as Links in v1.26.0, with the href attribute. But with the change, you are removing leading slashes (/), and making paths relative which is breaking the navigation.

There are 2 issues,

  1. If we had absolute paths before, eg. /team/members, introducing the following code change makes this path relative and so it gets appended to the URL and doesn’t redirects to the correct page.
    // HeaderTabs.tsx
    
    function removeLeadingSlash(path: string) {
        return path.replace(/^\//, '');
      }
    ...
    component={Link}
    to={removeLeadingSlash(tab.id)}
    ...
    
  2. If I change it to relative path, if it is outside of nested Routes, it works fine. But if it is in a route element component, the redirection doesn’t work anymore. Though if we use the absolute path, and the leading slash is not removed, it works.

πŸ‘ Expected behavior

I wanted to understand the reason of introducing the method to remove leading slashes and make the path relative on purpose. Ideally, it should redirect to the correct path no matter if we pass absolute or relative path.

πŸ‘Ž Actual Behavior with Screenshots

It appends the path in the URL,

Screenshot 2024-05-31 at 16 22 50

πŸ‘Ÿ Reproduction steps

For any HeaderTab implementation,

  1. When I pass absolute path,

    const tabs = [
      { label: 'Tab 1', path: '/plugin-name' },
      { label: 'Tab 2', path: '/plugin-name/coverage' },
      { label: 'Tab 3', path: '/plugin-name/tab-3' },
    ];
    ...
    <HeaderTabs
          selectedIndex={selectedIndex}
           tabs={tabs.map(({ label, path, tabProps }) => ({
            id: path,
            label,
            tabProps,
          }))}
    />
    
  2. The issue remains the same even when I have relative paths,

    const tabs = [
      { label: 'Tab 1', path: '' },
      { label: 'Tab 2', path: 'coverage' },
      { label: 'Tab 3', path: 'tab-3' },
    ];
    ...
    <HeaderTabs
          selectedIndex={selectedIndex}
           tabs={tabs.map(({ label, path, tabProps }) => ({
            id: path,
            label,
            tabProps,
          }))}
    />
    

For 2, the issue occurs when I use the above code inside Content.tsx from below (because Content gets re-rendered on click of tab and it updates the href),

```
<Routes>
  <Route path="/" element={<DashboardContent />} />
  <Route
    path="/content"
    element={<Content />}
  />
</Routes>
```

πŸ“ƒ Provide the context for the Bug.

No response

πŸ–₯️ Your Environment

OS: Darwin 23.4.0 - darwin/arm64 node: v18.18.0 yarn: 1.22.19 cli: 0.26.6 (installed) backstage: 1.27.5

@backstage/core-components: 0.14.7

πŸ‘€ Have you spent some time to check if this bug has been raised before?

  • I checked and didn’t find similar issue

🏒 Have you read the Code of Conduct?

Are you willing to submit PR?

Yes I am willing to submit a PR!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 17 (9 by maintainers)

Most upvoted comments

Thanks for sharing @malhotraashna. I added a β€œneeds-discussion” label to review the extended uses cases with our team.