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
[Banner] Measure contentNode
on change rather than window.onResize
#11974
Conversation
1d17f10
to
d5321a0
Compare
ResizeObserver
to measure contentNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! 🎉
Would you be able to /snapit
and do a quick tophat in the admin? Storybook looked good.
Also I noticed there was a flash when expanding the content where there is a render of the new content before the icon is adjusted. Its not blocking but I wonder how we could fix this 🤔
https://github.com/Shopify/polaris/assets/20652326/4d4731ef-63ff-434a-b9f7-6583b8166d23
/snapit |
🫰✨ Thanks @LA1CH3! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/polaris-migrator": "0.0.0-snapshot-20240503143333",
"@shopify/polaris": "0.0.0-snapshot-20240503143333",
"@shopify/polaris-tokens": "0.0.0-snapshot-20240503143333",
"@shopify/stylelint-polaris": "0.0.0-snapshot-20240503143333" |
@sophschneider I see that issue too 🤔 I have switched to use an unwrapped (as in, not wrapped in You can view the updated storybook link here. |
/snapit |
🫰✨ Thanks @LA1CH3! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/polaris-migrator": "0.0.0-snapshot-20240503151856",
"@shopify/polaris": "0.0.0-snapshot-20240503151856",
"@shopify/polaris-tokens": "0.0.0-snapshot-20240503151856",
"@shopify/stylelint-polaris": "0.0.0-snapshot-20240503151856" |
@sophschneider I've included a web + snapshot link in the PR for tophatting in the admin. Lmk what you think about the callback ref approach. |
ResizeObserver
to measure contentNode
contentNode
on change rather than window.onResize
36aa8b7
to
a74ce3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great @LA1CH3!
.changeset/weak-crabs-arrive.md
Outdated
'@shopify/polaris': patch | ||
--- | ||
|
||
Use callback ref to more accurately detect content changes in Banner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use callback ref to more accurately detect content changes in Banner | |
Fixed `Banner` not accurately detecting content changes |
Hey @chloerice so it actually looks like the issue was because when the callback ref was running on initial render, I think the best way to tackle this in response to any of the elements changing is to use |
Closing in favor of https://github.com/Shopify/polaris-internal/pull/65 |
WHY are these changes introduced?
Closes #11770
This PR fixes an issue where the
blockAlign
value was not being properly updated whencontentNode.offsetHeight
would change. This was because the measurement/calculation would only trigger onwindow.resize
, and would not trigger via other actions (such as a banner having content dynamically added/removed).WHAT is this pull request doing?
I've fixed this by using
ResizeObserver
to trigger recalculation whenevercontentNode
is resized, rather than the currenthandleResize
which is only triggered onwindow.resize
.How to 🎩
Storybook link
Web w/ snapshot
This includes an example story where the banner content is dynamically changed, resulting in
contentNode
changes, and triggering the correctblockAlign
property applied.🎩 checklist
README.md
with documentation changes