Skip to content
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

Use ResizeObserver and MutationObserver to detect detach/attach/resize #7104

Merged
merged 4 commits into from Feb 17, 2020

Conversation

kurkle
Copy link
Member

@kurkle kurkle commented Feb 14, 2020

@benmccann
Copy link
Contributor

I don't actually see ResizeObserver or MutationObserver in the diff anywhere. Are you sure they're included? Or let me know where they are if I'm missing them...

Does this add 5kb to the minified or unminified build? In either case, I'd be in favor of it to get the simplification of not needing to worry about the CSS extraction and inclusion anymore

@kurkle
Copy link
Member Author

kurkle commented Feb 14, 2020

src/platform/platform.dom.js

@benmccann
Copy link
Contributor

Ah, thanks. It looked like that file was deleted.

There's a few places with commented out code and debug logging, but other than that it generally looks good to me. I'm not the most familiar with the resize stuff, so I don't have much opinion on whether this would work better/worse, but I do like the idea of removing the CSS stuff

@kurkle
Copy link
Member Author

kurkle commented Feb 14, 2020

I think the only part that could be worse is attach detection.
That could be improved by allowing the dev to give a node under which the chart will be attached (thus reducing the tree to monitor)

Would need a complex test to see if that is an issue or not.

Another thing is the ResizeObserver polyfill. It supports < IE11, so I think that could be made thinner.

@@ -29,13 +28,12 @@ module.exports = [
resolve(),
commonjs(),
babel(),
stylesheet({
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should add something to the migration guide about the stylesheet and disableCSSInjection flag no longer being available?

@kurkle kurkle force-pushed the responsive branch 2 times, most recently from bb71df1 to b81c8a7 Compare February 16, 2020 09:35
@kurkle kurkle marked this pull request as ready for review February 16, 2020 09:58
Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

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

I'm not sure this is the right change to make. It took a lot of time to get to the current solution that worked in all cases for all browsers. I haven't looked at the implementation of the ResizeObserver polyfill but if it's not doing what we current do with two large divs, it likely doesn't work in all scenarios.

src/core/core.controller.js Outdated Show resolved Hide resolved
src/platform/platform.dom.js Show resolved Hide resolved
@kurkle
Copy link
Member Author

kurkle commented Feb 16, 2020

but if it's not doing what we current do with two large divs..

Not sure what you mean? (both pens are of use cases master can't handle)

@etimberg
Copy link
Member

I mean in terms of detecting a resize, how does the resize observer polyfill do it? The last time I researched this topic, the only two ways to do it performantly were the large divs + scroll events or using a hidden iframe.

@kurkle
Copy link
Member Author

kurkle commented Feb 16, 2020

I haven't looked at it close either. It uses MutationObserver and works in these 2 cases in IE.

Not sure if its possible to run IE in karma?

@etimberg
Copy link
Member

Looks like it might be possible using https://www.npmjs.com/package/karma-ie-launcher. Not sure how brittle it is

@kurkle
Copy link
Member Author

kurkle commented Feb 16, 2020

Looks like it might be possible using https://www.npmjs.com/package/karma-ie-launcher. Not sure how brittle it is

Can't get it to work. Needed to add babel() to karman properosessors, but then the utils is undefined, so it can't find acquireChart etc.

@benmccann
Copy link
Contributor

@etimberg there's some details here: https://github.com/que-etc/resize-observer-polyfill#observation-strategy It talks about why it didn't use the scroll strategy and also says it has no more than a 2-3% performance impact. Assuming that's true (and I don't have any reason to doubt it), I'd be pretty strongly in favor of this change. Even if it was much worse, I think we can take a bit of a performance hit on IE11 since it's an older browser and not as widely used

@etimberg
Copy link
Member

Thanks for linking that. Really helps to understand why this is a better choice.

Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

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

Implementation looks OK.

etimberg
etimberg previously approved these changes Feb 16, 2020

if (height === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check width === undefined || height === undefined ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe. I just tested the last parameter to detect missing params.

* Injects CSS styles inline if the styles are not already present.
* @param {Node} rootNode - the HTMLDocument|ShadowRoot node to contain the <style>.
* @param {string} css - the CSS to be injected.
* @param {Element} canvas
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be an HTMLCanvasElement ?

benmccann
benmccann previously approved these changes Feb 17, 2020
etimberg
etimberg previously approved these changes Feb 17, 2020
@kurkle kurkle dismissed stale reviews from etimberg and benmccann via da9d329 February 17, 2020 14:16
@kurkle
Copy link
Member Author

kurkle commented Feb 17, 2020

Found out regression to infinite resize in this PR and applied the same workaround.
For real use cases it would be best to use overflow-y: scroll in the window or other suitable parent.

@benmccann
Copy link
Contributor

@kurkle the tests seem to be failing now

@kurkle
Copy link
Member Author

kurkle commented Feb 17, 2020

Made 2 mistakes. Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants