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

Ensure tabs are available before selecting #97

Merged
merged 2 commits into from
Jun 19, 2024
Merged

Conversation

camertron
Copy link
Contributor

We experienced an error thrown from this element in dotcom today:

RangeError: Index "0" out of bounds

Our error reporting system indicated the error was thrown in selectTab, which was called from connectedCallback. It's not entirely clear what's happening, but one possible cause is that the list of tabs may not be available when connectedCallback is invoked. This PR uses a MutationObserver to ensure that the tabs are available before calling selectTab. This will hopefully prevent the error from occurring. I also removed the throw statement in question, opting instead for an early return.

@camertron camertron requested a review from a team as a code owner June 18, 2024 22:15
Copy link
Member

@keithamus keithamus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@camertron
Copy link
Contributor Author

The tests are not happy. It looks like the mutation observer never fires 😒

@camertron camertron requested a review from keithamus June 19, 2024 17:18
@camertron
Copy link
Contributor Author

Ok, I updated the PR to consider setup complete only after the entire selectTab function as run. If there are zero tabs, the early return in selectTab should prevent #setupComplete from being set to true, meaning the next time a tab is clicked (or a mutation occurs), the component should attempt setup again.

@camertron camertron merged commit 98f5d77 into main Jun 19, 2024
1 check passed
@camertron camertron deleted the ensure_tabs_available branch June 19, 2024 20:36
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