Lit-html: Add global variable for framework detection

Created on 4 Feb 2019  路  4Comments  路  Source: Polymer/lit-html

Something like: window.litHtmlVersions which will be an array of the versions used in a page.

Critical Enhancement

Most helpful comment

@oyvindeh you actually can't safely run multiple _interacting_ instances of lit-html together, because we use instanceof type checks in various places. if you send an object from one instance of lit-html to be rendered by another, you'll get bad output. You could however run multiple non-interacting instances of lit-html, because other than this change, we don't have any global state.

Tracking multiple versions will help diagnose problems with multiple instances.

All 4 comments

Out of curiosity, is this only necessary to detect the possible duplicate versions? That's unfortunate that ES module oriented library defines something in global namespace.

Can this be wrapped in development mode check so that code could be stripped out by minification tools in production, i.e. how some other existing libraries do?

Question: Given that window.litHtmlVersions is plural, I assume that one can safely run multiple instances/versions of lit-html independently on the same web page?

Is there anything one should be aware of when doing so?

@oyvindeh you actually can't safely run multiple _interacting_ instances of lit-html together, because we use instanceof type checks in various places. if you send an object from one instance of lit-html to be rendered by another, you'll get bad output. You could however run multiple non-interacting instances of lit-html, because other than this change, we don't have any global state.

Tracking multiple versions will help diagnose problems with multiple instances.

@web-padawan we really don't want this stripped out in production, because then we couldn't detect that a page uses lit-html.

Was this page helpful?
0 / 5 - 0 ratings