Skip to content

scrollable pane null ref check to resolve "Failed to execute 'getComputedStyle' on 'Window'" bug#4039

Merged
dzearing merged 8 commits intomicrosoft:masterfrom
davidcozsmith:davsm.scrollable-pane-null-ref-check
Feb 21, 2018
Merged

scrollable pane null ref check to resolve "Failed to execute 'getComputedStyle' on 'Window'" bug#4039
dzearing merged 8 commits intomicrosoft:masterfrom
davidcozsmith:davsm.scrollable-pane-null-ref-check

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Feb 20, 2018

…(root) in _resizeContainer

Pull request checklist

Description of changes

Fix Scrollable-Pane._resizeContainer null reference when calling getComputedStyle. This change checks this.refs.root and this.refs.stickyContainer for null before using them. See related bug.

Focus areas to test

Make sure Scrollable-Pane still renders and resizes correctly.
NOTE: When root or stickyContainer is null or undefined, this change makes the assumption that its ok to do nothing.

@ghost ghost changed the title Davsm.scrollable pane null ref check scrollable pane null ref check Feb 20, 2018
@ghost ghost changed the title scrollable pane null ref check scrollable pane null ref check to resolve "Failed to execute 'getComputedStyle' on 'Window'" bug Feb 20, 2018
}
if (borderLeftWidth) {
stickyContainer.style.left = root.offsetLeft + parseInt(borderLeftWidth, 10) + 'px';
if (root && stickyContainer) {
Copy link
Copy Markdown
Member

@dzearing dzearing Feb 21, 2018

Choose a reason for hiding this comment

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

This may be hiding the root cause. Why is the function being called when refs are null?

I believe it's because there is a setTimeout calling it after an unmount.

If you replace this:

setTimeout(() => this._resizeContainer(), 500);

With:

this._async.setTimeout(...)

Then the async helper will auto cancel the timeout on unmount and you won't have a function call doing potentially dangerous things.

Copy link
Copy Markdown
Author

@ghost ghost Feb 21, 2018

Choose a reason for hiding this comment

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

Ah. didnt see this till after I submitted the clearTimeout changes. Will do.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This._async.setTimeout worked perfect

@dzearing dzearing self-assigned this Feb 21, 2018
Copy link
Copy Markdown
Member

@dzearing dzearing left a comment

Choose a reason for hiding this comment

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

Check why _resizeContainer is called in unmounted scenarios. Fix that instead of checking for null.

@dzearing dzearing merged commit a40160d into microsoft:master Feb 21, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScrollablePane tries to getComputedStyle(root), but root is undefined (this.refs.root)

1 participant