diff options
author | Artur <artur@vaadin.com> | 2017-04-19 17:23:20 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-04-19 17:23:20 +0300 |
commit | 7d75f33707c5a88b65c429f34c4025910f243d35 (patch) | |
tree | eec15756f4e36b135f3d20a4214e5bdca83807f0 | |
parent | 8b95318c6c700c946478567193cb0e3040c1dad2 (diff) | |
download | vaadin-framework-7d75f33707c5a88b65c429f34c4025910f243d35.tar.gz vaadin-framework-7d75f33707c5a88b65c429f34c4025910f243d35.zip |
Wait for HTML imports to be processed and not only loaded (#9110)
Failing to do this might cause constructors and listeners in a Polymer
element too be called too early in browsers which need the V1 polyfill.
-rw-r--r-- | client/src/main/java/com/vaadin/client/ResourceLoader.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/ResourceLoader.java b/client/src/main/java/com/vaadin/client/ResourceLoader.java index 69cb11dc9f..d1f615a068 100644 --- a/client/src/main/java/com/vaadin/client/ResourceLoader.java +++ b/client/src/main/java/com/vaadin/client/ResourceLoader.java @@ -249,7 +249,10 @@ public class ResourceLoader { addOnloadHandler(linkTag, new ResourceLoadListener() { @Override public void onLoad(ResourceLoadEvent event) { - fireLoad(event); + // Must wait for all HTML imports to finish + // processing to ensure that e.g. the template is + // parsed when calling the element constructor. + runWhenHtmlImportsReady(() -> fireLoad(event)); } @Override @@ -465,4 +468,28 @@ public class ResourceLoader { private static Logger getLogger() { return Logger.getLogger(ResourceLoader.class.getName()); } + + private static native boolean supportsHtmlWhenReady() + /*-{ + return !!($wnd.HTMLImports && $wnd.HTMLImports.whenReady); + }-*/; + + private static native void addHtmlImportsReadyHandler(Runnable handler) + /*-{ + $wnd.HTMLImports.whenReady($entry(function() { + handler.@Runnable::run()(); + })); + }-*/; + + protected void runWhenHtmlImportsReady(Runnable runnable) { + if (GWT.isClient() && supportsHtmlWhenReady()) { + addHtmlImportsReadyHandler(() -> { + runnable.run(); + }); + } else { + runnable.run(); + } + + } + } |