-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 useResizeObserver
bugs
#65389
Fix useResizeObserver
bugs
#65389
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Following up on the discussion here: #64943 (review) cc @jsnajdr Regarding React Native, I don't think this utility should try to cover that use case. |
Size Change: +159 B (+0.01%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
What if React Native module imports import { useResizeObserver } from '@wordpress/compose'; ? Then it also imports the web version of the new hook, and that hook can be called as |
I see the point about React Native, however I wonder, do all
What do you think? |
There are two separate index files, All I'm asking for is that there is a new You don't need to write any new code or remove anything. Just exclude the web version of |
This makes sense to me, but if in doubt, we can always ping some folks from the mobile team for confirmation. |
@jsnajdr alright, that makes sense though there are some details to discuss. For example, what happens with the difference in API. The new API is web-only so it won't be possible to re-create for React Native in any case. Will that be okay? Anyway, I'm merging this but let's keep discussing and I'll open a new PR to handle that. |
At this moment, the React Native API stays the same. There is the It should be possible to implement a pretty good version of the new API also for React Native. function useResizeObserver( callback ) {
const elRef = useRef();
const cb = useEvent( callback );
useEffect( () => {
function handleLayout( e ) {
const entries = [ { contentBoxSize: [ { inlineSize: e.layout.width, blockSize: e.layout.height } ] } ];
cb( entries );
}
const el = elRef.current;
el.addEventListener( 'layout', handleLayout );
return () => el.removeEventListener( 'layout', handleLayout );
} );
return elRef;
} The existing RN usages of There are details to figure out like whether the reported layout is |
Just to understand, with this PR merged, is there a chance that the native APIs got a breaking change? If so, we should make sure we quickly put up a PR to export only the legacy version to react native, as proposed by Jarda above. |
@ciampo nothing that already is in use will break. I will put up a PR that handles the React Native situation very soon, but don't worry about it as there's no chance new code will be submitted that breaks, as the error would be immediate. This PR doesn't affect the React Native situation fwiw, it just addresses some bugs and tweaks related to the web version. |
* Rename "_legacy" dir to "legacy" * Fix circular dependency issue * Fix bug that caused elements to not be unobserved. * Add changelog * Remove changelog entry Co-authored-by: DaniGuardiola <[email protected]> Co-authored-by: jsnajdr <[email protected]> Co-authored-by: tyxla <[email protected]>
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: d87b39b |
See #65588 |
What?
_legacy
dir to justlegacy
Thanks @jsnajdr! Original post-merge review: #64943 (review)