domino
domino copied to clipboard
Minifier breaks library
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 :)
I'm hitting this issue as well. Is there a work around?
see #151
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.
Found a workaround for terser: add the keep_fnames: /^(HTML|SVG)/ option.
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.