Skip to content
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

[EuiTabbedContent] TypeError: Cannot read property 'content' of undefined #7350

Closed
daradermody opened this issue Nov 8, 2023 · 3 comments · Fixed by #7713
Closed

[EuiTabbedContent] TypeError: Cannot read property 'content' of undefined #7350

daradermody opened this issue Nov 8, 2023 · 3 comments · Fixed by #7713
Labels
bug good first issue help wanted The EUI team is looking for community members to pick up and implement this issue

Comments

@daradermody
Copy link

daradermody commented Nov 8, 2023

Describe the bug
The EuiTabbedContent throws a type error when the tabs prop changes to a new (and different) list of tabs.

Impact and severity
Low impact because the workaround is easy. Adding key={uniqueStringAssociatedWithTabsList} causes the component to remount and therefore reinitialize its state based on the new tabs list.

Environment and versions

  • EUI version: 91.0.0
  • React version: 18.2.0
  • Browser: Chrome 117.0.5938.149
  • Operating System: Ubuntu 22.04.3

To Reproduce

  1. Render an EuiTabbedContent component with one set of tabs
  2. Cause a rerender that then uses another different set of tabs

Expected behavior
Tabs should refresh to be the new ones, and the first tab is selected.

Minimum reproducible sandbox
https://codesandbox.io/s/reactjs-playground-forked-f2ysd2

Additional context
Found this similar bug, but didn't seem to be the exact same issue.

The issue is caused by the fact that the selected tab ID is stored in state and is initalised on construction of the component based on the props of the first render (here). During the first render, it's used to fetch the appropriate tab from the tabs list (here). However, when we change the tabs prop, a rerender is triggered, but the state of selectedTabId is not updated based on the new set of IDs, so that find() returns undefined, and the type error is thrown when we try to access content (here),

@daradermody daradermody added bug ⚠️ needs validation For bugs that need confirmation as to whether they're reproducible labels Nov 8, 2023
@tkajtoch tkajtoch added good first issue help wanted The EUI team is looking for community members to pick up and implement this issue and removed ⚠️ needs validation For bugs that need confirmation as to whether they're reproducible labels Nov 9, 2023
Copy link

github-actions bot commented Nov 9, 2023

👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.

@tkajtoch
Copy link
Member

tkajtoch commented Nov 9, 2023

Thanks for reporting this and including so many helpful details! I was able to reproduce it locally.

Replacing tabs in the runtime is pretty unusual, and I agree it has a low impact. We'll try to implement a fix soon, but we're happy to accept community contributions on this in the meantime!

@tkajtoch
Copy link
Member

We're not planning to work on this bug in the near future. It's an edge case, and there's a workaround available. As always, community contributions are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue help wanted The EUI team is looking for community members to pick up and implement this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants