Skip to content

[Banner] Refactor to a functional component and fix its id server/client mismatch #3199

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

Merged
merged 3 commits into from
Sep 11, 2020

Conversation

Tom-Bonnike
Copy link
Contributor

@Tom-Bonnike Tom-Bonnike commented Aug 26, 2020

WHY are these changes introduced?

We’re getting server/client id mismatches on the Admin dashboard on pages that use Banners. This is because the current way of generating unique ids is not foolproof.

WHAT is this pull request doing?

The first commit is refactoring Banner to a functional component since we can’t use hooks in class components.
The second commit fixes the id server/client mismatch by using the useUniqueId hook instead of the Banner’s custom uniqueID() util.

How to 🎩

We can’t 🎩 the bug fix on the Playground since it’s not server-side rendered.

Here‘s how I tested it:

  • Go to a page on your local web that renders a Banner; I used /admin/settings/payments. Notice how there’s a warning in the console that looks like this one:

Screenshot 2020-08-26 at 15 53 03

  • Checkout the fix-mismatch-banner-ids branch on polaris-react
  • Run yarn build then yarn build-consumer web
  • Restart your web server then refresh the page on /admin/settings/payments, notice how there’s no more warning in the console

I think relying on automated testing for the rest is OK here as I’m not really changing any behaviour/styles, just implementation details: the unit tests & visual regression tests are passing.
Let me know if you still want me to go through the regular 🎩 checklist.

@ghost
Copy link

ghost commented Aug 26, 2020

👋 Thanks for opening your first pull request. A contributor should give feedback soon. If you haven’t already, please check out the contributing guidelines.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2020

🟢 No significant changes to src/**/*.tsx were detected.

@Tom-Bonnike Tom-Bonnike force-pushed the fix-mismatch-banner-ids branch from 4ab8f3e to 86dfd9f Compare August 26, 2020 12:24
@Tom-Bonnike Tom-Bonnike force-pushed the fix-mismatch-banner-ids branch 2 times, most recently from 14f2ff7 to 43f809f Compare August 26, 2020 12:42
UNRELEASED.md Outdated
@@ -12,6 +12,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Bug fixes

- Fix `Banner`’s `id` server/client mismatch ([#3199](https://github.com/Shopify/polaris-react/pull/3199)).
Copy link
Contributor Author

@Tom-Bonnike Tom-Bonnike Aug 26, 2020

Choose a reason for hiding this comment

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

Moving from a class to a functional component is probs not worth an entry in Code quality?

@Tom-Bonnike Tom-Bonnike changed the title Refactor Banner to a functional component and fix its id server/client mismatch [Banner] Refactor to a functional component and fix its id server/client mismatch Aug 26, 2020
@Tom-Bonnike Tom-Bonnike marked this pull request as ready for review August 26, 2020 14:07
wrapperRef.current?.focus();
setShouldShowFocus(true);
},
}));
Copy link
Contributor Author

@Tom-Bonnike Tom-Bonnike Aug 26, 2020

Choose a reason for hiding this comment

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

I tried it and it seems to still work great! You can paste this in the Playground to 🎩:

import React from 'react';

import {Page, Banner} from '../src';

export function Playground() {
  const bannerRef = React.useRef();

  React.useEffect(() => {
    bannerRef.current?.focus();
  }, []);

  return (
    <Page title="Playground">
      <Banner ref={bannerRef} title="Some banner title" />
    </Page>
  );
}

@Tom-Bonnike Tom-Bonnike added ⚗️ Development Bug Something is broken and not working as intended in the system. labels Aug 26, 2020
@BPScott
Copy link
Member

BPScott commented Aug 28, 2020

Yay thanks for doing this! I've not had time to review yet, but shall try and get to it early next week

Copy link
Member

@chloerice chloerice left a comment

Choose a reason for hiding this comment

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

Thanks for contributing, @Tom-Bonnike, the code looks great! I tried to tophat in web, but in order to get dev up working I had to reset railgun so I didn't have any banners visible because my data is so bare. The tophat in Chroma looks solid with and without the new design lang enabled 🚢

Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

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

Note to self: When telling people you'll review something at the start of the week remember that the first half of your week is full of meetings.

Thanks for doing this and sorry for the delay!

I've dropped a few comments inline. The important one that needs to be fixed is adding the role=status to non-critical/non-warning banners as you pointed out. Turns out we did that before but it got lost in the refactoring :)

@Tom-Bonnike Tom-Bonnike force-pushed the fix-mismatch-banner-ids branch 4 times, most recently from db6e512 to ce5c4ba Compare September 4, 2020 08:35
@Tom-Bonnike Tom-Bonnike requested a review from BPScott September 4, 2020 08:55
@Tom-Bonnike
Copy link
Contributor Author

Thanks for the reviews! Applied your comments @BPScott, good catch on that aria role 🙈

expect(banner.find(Icon).prop('source')).toBe(FlagMajorTwotone);
expect(banner.find(Icon).prop('color')).toBe('inkLighter');
});

Copy link
Contributor Author

@Tom-Bonnike Tom-Bonnike Sep 4, 2020

Choose a reason for hiding this comment

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

I moved that up with the other icon/role tests and added the role assertions to those as well.

@Tom-Bonnike Tom-Bonnike force-pushed the fix-mismatch-banner-ids branch from 5548b91 to a73076d Compare September 10, 2020 06:20
@Tom-Bonnike Tom-Bonnike self-assigned this Sep 10, 2020
Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

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

Thanks for being patient while I was on holiday these past few days. Fantastic work, looks all great to me!

Polaris convention is that you merge your own PRs once you're happy with them (the polaris-team being the ones that merge would imply we're some kind of gatekeepers which we absolutely don't want to encourage - everyone should feel like they own this codebase) so :shipit: when you're happy

good catch on that aria role

There's a very real chance I would have totally missed it if not for your initial pondering around that, so thank you for pointing it out!

@Tom-Bonnike Tom-Bonnike force-pushed the fix-mismatch-banner-ids branch from a73076d to fb75003 Compare September 11, 2020 07:25
@Tom-Bonnike
Copy link
Contributor Author

Tom-Bonnike commented Sep 11, 2020

Thanks! Cool. I’ll merge as soon as CI passes. I’m guessing y’all are still responsible for releasing the new versions?

@Tom-Bonnike Tom-Bonnike merged commit cdedbd6 into master Sep 11, 2020
@Tom-Bonnike Tom-Bonnike deleted the fix-mismatch-banner-ids branch September 11, 2020 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken and not working as intended in the system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants