-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix useResizeObserver loop limit exceeded warning #2891
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
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0681218
Fix useResizeObserver loop limit exceeded warning
snowystinger a3dba5f
Make a build with the reproduction
snowystinger 5d7a392
Add logic to see if we should stop observing
snowystinger c316179
fix types
snowystinger 05c485f
Merge branch 'main' into fix-resizeobserver-warning
snowystinger bb55341
Merge branch 'main' into fix-resizeobserver-warning
snowystinger adae00b
Merge branch 'main' into fix-resizeobserver-warning
snowystinger 1207431
Merge branch 'main' into fix-resizeobserver-warning
snowystinger 258cff6
use raf instead of unobserve
snowystinger 395334c
add comment
snowystinger 356f8c5
Merge branch 'main' into fix-resizeobserver-warning
snowystinger b58261e
Merge branch 'main' into fix-resizeobserver-warning
snowystinger ab1b931
clean up refs
snowystinger 6c2f397
Merge branch 'main' into fix-resizeobserver-warning
snowystinger 0fa77cf
fix potential scenario where we never fire onResize
snowystinger 05922ff
Merge branch 'main' into fix-resizeobserver-warning
snowystinger 366b46d
Merge branch 'main' into fix-resizeobserver-warning
LFDanLu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/@react-aria/utils/stories/useResizeObserver.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
|
|
||
| import {Button} from '@react-spectrum/button'; | ||
| import {Meta, Story} from '@storybook/react'; | ||
| import React, {useEffect, useRef, useState} from 'react'; | ||
| import {useResizeObserver} from '../src'; | ||
|
|
||
| export default { | ||
| title: 'useResizeObserver' | ||
| } as Meta; | ||
|
|
||
| const Template: Story<any> = () => ( | ||
| <App /> | ||
| ); | ||
|
|
||
| export const UseResizeObserverLoopLimit = Template.bind({}); | ||
| UseResizeObserverLoopLimit.args = {}; | ||
|
|
||
| const animalSet = ['🐰', '🦊', '🐻', '🐭', '🐼', '🐸']; | ||
| function App() { | ||
| let ref = useRef<HTMLDivElement>(); | ||
| let index = useRef(0); | ||
| let [animals, setAnimals] = useState([animalSet[0]]); | ||
|
|
||
| function insertAnimal() { | ||
| index.current = index.current + 1; | ||
| setAnimals(prev => [...prev, animalSet[index.current % animalSet.length]]); | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| let onError = (err) => { | ||
| console.log(err); | ||
| }; | ||
| window.addEventListener('error', onError); | ||
| return () => { | ||
| window.removeEventListener('error', onError); | ||
| }; | ||
| }, []); | ||
|
|
||
| let onResize = () => { | ||
| const {width} = ref.current.getBoundingClientRect(); | ||
|
|
||
| ref.current.style.height = `${width}px`; | ||
| }; | ||
|
|
||
| useResizeObserver({onResize, ref}); | ||
|
|
||
| return ( | ||
| <> | ||
| <div ref={ref} id="red-box"> | ||
| {animals} | ||
| </div> | ||
| <Button variant="primary" onPress={insertAnimal}>Insert Next Animal</Button> | ||
| </> | ||
| ); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.