domino icon indicating copy to clipboard operation
domino copied to clipboard

Minifier breaks library

Open fluidsonic opened this issue 6 years ago • 5 comments

I just came a cross an interesting problem when deploying an Angular SSR application where I kept getting this error:

Uncaught (in promise) TypeError: StaticInjectorError[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
  StaticInjectorError(Platform: core)[InjectionToken Application Initializer -> InjectionToken DocumentToken]: 
    Right-hand side of 'instanceof' is not an object
    at _t (VM10 worker.js:73658)
    at yt (VM10 worker.js:73649)
    at ir (VM10 worker.js:75978)
    at ze.insertToken (VM10 worker.js:73618)
    at VM10 worker.js:73777
    at Ot (VM10 worker.js:73778)
    at Ke (VM10 worker.js:73504)
    at Object.parse (VM10 worker.js:73454)
    at Object.t.createDocument (VM10 worker.js:63806)
    at Object.t.createWindow (VM10 worker.js:63830)

After a lot of digging it turned out that some parent instanceof impl.HTMLTemplateElement failed because impl.HTMLTemplateElement was undefined. After some more digging I found that elements are defined like this:

  ctor: function HTMLTemplateElement(doc, localName, prefix) {
    HTMLElement.call(this, doc, localName, prefix);
    this._contentFragment = doc._templateDoc.createDocumentFragment();
  },

The name of the function is used for the key in the elements object.

Unfortunately some minifiers remove those names to further decrease size, so the name cannot be used anymore by the library and it breaks completely. I've found that Mozilla even warns about exactly that problem.

I suggest to pass the name as a regular string rather than using the function's name for sake of reliability :)

fluidsonic avatar Sep 28 '19 08:09 fluidsonic

I'm hitting this issue as well. Is there a work around?

randallmeeker avatar Oct 28 '19 14:10 randallmeeker

see #151

nidi3 avatar Nov 17 '19 20:11 nidi3

As the project seems to be sleeping at the moment, I published a build with this fix on npm https://www.npmjs.com/package/domino-ext. But I would like to see it applied here on the original.

nidi3 avatar Nov 18 '19 10:11 nidi3

Found a workaround for terser: add the keep_fnames: /^(HTML|SVG)/ option.

silverwind avatar Apr 08 '20 20:04 silverwind

I'm waiting for #151 to be cleaned up so it is possible to apply it. Generally speaking, a broken minifier is not a bug in domino.

cscott avatar Apr 30 '20 22:04 cscott