manolo / gwt-polymer-elements

Polymer Web Components for GWT. A collection of Material Design widgets for desktop and mobile.
Apache License 2.0
155 stars 49 forks source link

Not importing the polyfills break whenReady in Polymer.java #135

Closed Xaratas closed 7 years ago

Xaratas commented 7 years ago

I will not hijack #112. But its somehow related.

Problem: If the polyfills are not loaded (because chrome is used), then your gwt bridge will not load the webcomponents polyfill by itself and try to call whenReady on undefined, because chrome does not natively create a HTMLImport „something“ in the window.

Code Reference: This line uses $wnd.HTMLImport.whenready https://github.com/vaadin/gwt-polymer-elements/blob/vaadin-gwt-polymer-elements-1.2.3.0/src/main/java/com/vaadin/polymer/Polymer.java#L364

We use the (general) platform check to include webcomponents polyfill only when necessary.

    if ('registerElement' in document
              && 'import' in document.createElement('link')
              && 'content' in document.createElement('template')) {
        loadElements();
     } else {
        // polyfill the platform!
        showMessage("Komponenten werden geladen...");
        var e = document.createElement('script');
        e.src = 'bower_components/webcomponentsjs/webcomponents-lite.min.js';
        document.body.appendChild(e);

        window.addEventListener('WebComponentsReady', function(e) {
            loadElements();
        });
    }

As we want to use the platform (remember the summit ;) ) is there a workaround or fix possible?

manolo commented 7 years ago

We are about to release 1.7.0.0, scheduled to next week, and had not thought on this before. The current approach loads the polyfill when it is not loaded in order to have the whenReady. Although loading the polyfill in chrome is not a big deal because the polyfill skips patching everything that already is in the platform, probably there is a better approach and not load it at all. I don't think it is a big performance improvement, but will try to come with a solution today.

manolo commented 7 years ago

Fixed in Polymer.java, now it loads the polyfill only if the browser does not support native html imports. Obviously it also checks whether the polyfill was already loaded in order not to load twice. Use 1.7.0.0-SNAPSHOT until 1.7.0.0 is released next week. You can check out our demo http://vaadin.github.io/gwt-polymer-elements/demo and inspect that polyfil is not loaded in chrome, but in other browsers.