Skip to content

Commit

Permalink
Fix flow-component-renderer for Chrome 72
Browse files Browse the repository at this point in the history
  • Loading branch information
pleku committed Feb 14, 2019
1 parent f267ff2 commit ce32fd1
Showing 1 changed file with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,61 @@
'_attachRenderedComponentIfAble(appid, nodeid)'
]
}


connectedCallback() {
super.connectedCallback();
this._runChrome72ShadowDomBugWorkaround();
}

/* workaround for issue vaadin/flow#5025 */
_runChrome72ShadowDomBugWorkaround() {
const userAgent = navigator.userAgent;
if (userAgent && userAgent.match('Chrome\/')) {
// example: ... Chrome/72.0.3626.96 ...
const majorVersionString = userAgent.split('Chrome\/')[1].split('.')[0];
this.style.visibility = 'hidden';
if (majorVersionString && parseInt(majorVersionString) > 71) {

const debouncedNotifyResize = this._getDebouncedNotifyResizeFunction();

// if there is no notifyResize function, then just skip
if (debouncedNotifyResize) {
// need to use animation frame instead of timeout or focusing won't work
requestAnimationFrame(() => {
this.style.visibility = '';
debouncedNotifyResize();
});
}
}
}
}

_getDebouncedNotifyResizeFunction() {
// 1. dig out the web component that might have the notifyResize function
let component = this.parentElement;
while (true) {
if (!component) {
return;
}
if (component.notifyResize) {
break;
} else {
component = component.parentElement;
}
}
// 2. assign a debounced proxy to notifyResize, if not yet there
if (!component._debouncedNotifyResize) {
component._debouncedNotifyResize = function () {
component.__debouncedNotifyResize =
Polymer.Debouncer.debounce(
component.__debouncedNotifyResize, // initially undefined
Polymer.Async.animationFrame,
component.notifyResize);
}
}
return component._debouncedNotifyResize;
}

ready(){
super.ready();
this.addEventListener("click", function(event){
Expand Down

0 comments on commit ce32fd1

Please sign in to comment.