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

fix(navigation-bar): move context provider to not wrap parent #6960

Merged
merged 2 commits into from
Sep 20, 2024

Conversation

robinzigmond
Copy link
Contributor

The FixedNavigationBarContextProvider, which uses a ResizeObserver to respond to size changes on the navbar element, currently wraps that same element. This can result in unexpected ResizeObserver errors on initial render, when a media query is being used to determine layout. The context provider only needs to wrap the navbar's children, and by moving it down the React tree to only wrap the children and not the parent, the error goes away.

Proposed behaviour

No ResizeObserver errors should be raised when a NavigationBar component is rendered

Current behaviour

ResizeObserver errors are raised on initial render when padding is set by a media query

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Screenshots are included in the PR if useful
  • All themes are supported if required
  • Unit tests added or updated if required
  • Playwright automation tests added or updated if required
  • Storybook added or updated if required
  • Translations added or updated (including creating or amending translation keys table in storybook) if required
  • Typescript d.ts file added or updated if required
  • Related docs have been updated if required

QA

  • Tested in provided StackBlitz sandbox/Storybook
  • Add new Playwright test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Additional context

Testing instructions

A Test story has been added to demonstrate the bug scenario and allow manual testing - when run without the code change that fixes the issue, this results in an error message related to ResizeObserver being rendered on the screen. (In Safari, this can also be seen on the Javascript console.) With the fix in place, this error no longer appears (either on screen or in the console, in any browser).

When regression testing, please pay particular attention to the NavigationBarWithSubmenuAndChangingHeight test story, as this is the one most likely to have been affected by this change (but I do not believe it will have been).

The FixedNavigationBarContextProvider, which uses a ResizeObserver to respond to size changes on the
navbar element, currently wraps that same element. This can result in unexpected ResizeObserver
errors on initial render, when a media query is being used to determine layout. The context provider
only needs to wrap the navbar's children, and by moving it down the React tree to only wrap the
children and not the parent, the error goes away.
Copy link
Contributor

@nineteen88 nineteen88 left a comment

Choose a reason for hiding this comment

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

The change on the surface seems fine, just not sure whether it will have any knock of effects. If there's any issues though, it should flag up in QA so happy to approve

@edleeks87 edleeks87 marked this pull request as ready for review September 18, 2024 16:22
@edleeks87 edleeks87 requested review from a team as code owners September 18, 2024 16:22
@robinzigmond robinzigmond merged commit c1f9a8c into master Sep 20, 2024
24 checks passed
@robinzigmond robinzigmond deleted the resize-observer-fix branch September 20, 2024 15:06
@carbonci
Copy link
Collaborator

🎉 This PR is included in version 142.11.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

6 participants