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: Prevent breadcrumbs from flickering when rendered inside app layout toolbar breadcrumbs slot #2895

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

just-boris
Copy link
Member

@just-boris just-boris commented Oct 17, 2024

Description

Follow up for #2892.

When breadcrumbs are already rendered in the expected slot, there is no need for the runtime API interactions. This allows for a fast track without additional re-renders.

Related links, issue #, if available: n/a

How has this been tested?

  1. Updated relevant unit tests
  2. Tested the actual flickering locally on the dev page
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines +11 to +12
export const BreadcrumbsSlotContext =
awsuiPluginsInternal.sharedReactContexts.createContext<BreadcrumbsSlotContextType>(React, 'BreadcrumbsSlotContext');
Copy link
Member Author

Choose a reason for hiding this comment

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

This is needed, because by default React.createContext produces a new context for each call. In our case, there could be multiple copies of this file, which will not allow context providers connect to its consumers.

We solve it by caching context instances by their name

Copy link
Member

Choose a reason for hiding this comment

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

But we are guaranteed to have only one copy of SharedReactContexts —do I understand correctly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, because awsuiPluginsInternal object is deduplicated.

const existingApi = findUpApi(win);
win[storageKey] = installApi(existingApi ?? {});

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.21%. Comparing base (b22ec75) to head (cfc86a8).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #2895    +/-   ##
========================================
  Coverage   96.21%   96.21%            
========================================
  Files         761      763     +2     
  Lines       21511    21531    +20     
  Branches     7366     6972   -394     
========================================
+ Hits        20697    20717    +20     
- Misses        761      806    +45     
+ Partials       53        8    -45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -108,15 +115,17 @@ describeEachAppLayout({ themes: ['refresh-toolbar'], sizes: ['desktop'] }, () =>
);
});

test('when breadcrumbs are rendered in multiple slots, the last one takes precedence', async () => {
await renderAsync(
test('when breadcrumbs are rendered in multiple slots, the one in the breadcrumbs slot takes precedence', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Technically, this is a breaking change. But this the new expected one, we should be fine.

@just-boris just-boris marked this pull request as ready for review October 18, 2024 16:59
@just-boris just-boris requested a review from a team as a code owner October 18, 2024 16:59
@just-boris just-boris requested review from jperals and removed request for a team October 18, 2024 16:59
@just-boris just-boris added this pull request to the merge queue Oct 21, 2024
Merged via the queue into main with commit 7a4b7b3 Oct 21, 2024
39 checks passed
@just-boris just-boris deleted the global-breadcrumbs branch October 21, 2024 14:44
dpitcock pushed a commit that referenced this pull request Oct 23, 2024
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