From 534648c7c3b83b12e8956052d5ef2097610d63ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leif=20=C3=85strand?= Date: Fri, 17 Mar 2017 15:32:23 +0200 Subject: [PATCH] Use HTMLImports.whenReady for detecting HTML import loading When using the v1 polyfills, Polymer depends on the load event for some internal bookkeeping. This means that we cannot start using an imported web component if our load listener is registered before Polymer's load listener. Instead, we can use the HTMLImports.whenReady callback since it's fired only after Polymer has had a chance to register everything. Fixes vaadin/hummingbird-demo#203 --- .../java/com/vaadin/client/ResourceLoader.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hummingbird-client/src/main/java/com/vaadin/client/ResourceLoader.java b/hummingbird-client/src/main/java/com/vaadin/client/ResourceLoader.java index 146b06ff206..2d378a46d93 100644 --- a/hummingbird-client/src/main/java/com/vaadin/client/ResourceLoader.java +++ b/hummingbird-client/src/main/java/com/vaadin/client/ResourceLoader.java @@ -306,13 +306,27 @@ public void onError(ResourceLoadEvent event) { public static native void addOnloadHandler(Element element, ResourceLoadListener listener, ResourceLoadEvent event) /*-{ - element.onload = $entry(function() { + var eventFired = false; + var loadHandler = $entry(function() { + if (eventFired) { + return; + } + eventFired = true; element.onload = null; element.onerror = null; element.onreadystatechange = null; listener.@com.vaadin.client.ResourceLoader.ResourceLoadListener::onLoad(Lcom/vaadin/client/ResourceLoader$ResourceLoadEvent;)(event); }); + if ($wnd.HTMLImports && element.tagName === "LINK" && element.getAttribute("rel") === "import") { + $wnd.HTMLImports.whenReady(loadHandler); + } else { + element.onload = loadHandler; + } element.onerror = $entry(function() { + if (eventFired) { + return; + } + eventFired = true; element.onload = null; element.onerror = null; element.onreadystatechange = null;