-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Conversation
I don't actually see 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 |
src/platform/platform.dom.js |
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 |
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({ |
There was a problem hiding this comment.
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?
bb71df1
to
b81c8a7
Compare
There was a problem hiding this 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.
Not sure what you mean? (both pens are of use cases master can't handle) |
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. |
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? |
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 |
@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 |
Thanks for linking that. Really helps to understand why this is a better choice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks OK.
src/core/core.controller.js
Outdated
|
||
if (height === undefined) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
src/platform/platform.dom.js
Outdated
* 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 |
There was a problem hiding this comment.
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
?
Found out regression to infinite resize in this PR and applied the same workaround. |
@kurkle the tests seem to be failing now |
Made 2 mistakes. Fixed. |
This currently adds about 5kb, probably due to the ResizeObserver polyfill.
https://codepen.io/kurkle/pen/PoqZQxR
https://codepen.io/kurkle/full/ZEGQwrZ
https://codepen.io/kurkle/pen/WNvwKOm
https://codepen.io/kurkle/full/xxGVJmL
Fixes: #5805 #6145 #5158 #3979