-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: Use correct target windows for ResizeObserver #29551
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
ling1726
merged 9 commits into
microsoft:master
from
ling1726:fix/resize-observer-target-document
Oct 19, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c0a34e0
fix: Use correct target windows for ResizeObserver
ling1726 cbad8b6
changefile
ling1726 238123a
create new utility
ling1726 19ee69f
changefile
ling1726 b086d78
remove unnecessary
ling1726 abac215
revert utilities change
ling1726 3814355
add fixme
ling1726 cdc08b2
merge master
ling1726 9c2abd3
revert
ling1726 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
7 changes: 7 additions & 0 deletions
7
change/@fluentui-priority-overflow-10c22153-de2e-4c16-8fc0-b49aadbd1d08.json
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,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "fix: Use container window's resize observer", | ||
| "packageName": "@fluentui/priority-overflow", | ||
| "email": "lingfangao@hotmail.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-table-01e02e96-5aa2-493f-8614-61799987dce2.json
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,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "fix: use targetDocument resize observer", | ||
| "packageName": "@fluentui/react-table", | ||
| "email": "lingfangao@hotmail.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-virtualizer-6da34b46-57b4-4d39-92c6-b5abe95ef0c0.json
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,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "fix: use targetDocument resize observer", | ||
| "packageName": "@fluentui/react-virtualizer", | ||
| "email": "lingfangao@hotmail.com", | ||
| "dependentChangeType": "patch" | ||
| } |
25 changes: 25 additions & 0 deletions
25
packages/react-components/priority-overflow/src/createResizeObserver.ts
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,25 @@ | ||
| /** | ||
| * Helper function that creates a resize observer in the element's own window global | ||
| * @param elementToObserve - Uses the element's window global to create the resize observer | ||
| * @param callback | ||
| * @returns function to cleanup the resize observer | ||
| */ | ||
| export function observeResize(elementToObserve: HTMLElement, callback: ResizeObserverCallback) { | ||
| const GlobalResizeObsever = elementToObserve.ownerDocument.defaultView?.ResizeObserver; | ||
|
|
||
| if (!GlobalResizeObsever) { | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| // eslint-disable-next-line no-console | ||
| console.error('@fluentui/priority-overflow', 'ResizeObserver does not exist on container window'); | ||
| } | ||
| return () => null; | ||
| } | ||
|
|
||
| let resizeObserver: ResizeObserver | undefined = new GlobalResizeObsever(callback); | ||
| resizeObserver.observe(elementToObserve); | ||
|
|
||
| return () => { | ||
| resizeObserver?.disconnect(); | ||
| resizeObserver = undefined; | ||
| }; | ||
| } |
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
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
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
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
17 changes: 17 additions & 0 deletions
17
...ages/react-components/react-virtualizer/src/utilities/createResizeObserverFromDocument.ts
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,17 @@ | ||
| /** | ||
| * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar | ||
| * A utility method that creates a ResizeObserver from a target document | ||
| * @param targetDocument - document to use to create the ResizeObserver | ||
| * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback | ||
| * @returns a ResizeObserver instance or null if the global does not exist on the document | ||
| */ | ||
| export function createResizeObserverFromDocument( | ||
| targetDocument: Document | null | undefined, | ||
| callback: ResizeObserverCallback, | ||
| ) { | ||
| if (!targetDocument?.defaultView?.ResizeObserver) { | ||
| return null; | ||
| } | ||
|
|
||
| return new targetDocument.defaultView.ResizeObserver(callback); | ||
| } | ||
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.