Skip to content

[lit] Remove "Lit is in dev mode" warning #4877

@maxpatiiuk

Description

@maxpatiiuk

Should this be an RFC?

  • This is not a substantial change

Which package is this a feature request for?

Lit Core (lit / lit-html / lit-element / reactive-element)

Description

Lit emits a Lit is in dev mode warning when Lit is loaded using the development bundle, rather than production:

Image

I understand that this warning is useful for detecting cases when development mode of Lit is accidentally used in production, but I do not know how likely that is, or if it is worth the tradeoff.

From my understanding, Lit's dev mode is only enabled when the "development" export condition is set - thus, it is a quite deliberate opt-in step, so I am not sure how likely it is that development build is accidentally shipped to production.

Some negative consequences of this warning:

  • Clutteres the console, adding noise and distracting from real warnings/errors
  • Affects the console not only of the team working on a Lit package, but also of any consumer of that Lit-authored package - that is a lot of console noise. Some users might even be confused into thinking something is misconfigured/not working right because they see this warning
  • Cluttering the console is especially bad when running isolated tests, as each test spams the console with this warning
  • This warning can break tests. Many testing setups use jest-fail-on-console or vitest-fail-on-console to fail the test when any error or warning is emitted - Lit's warning falsely fails tests and requires special configuration to avoid
  • Some organizations have a 0 warning policy

Alternatives and Workarounds

I understand that this warning can be disabled by adding the following code:

globalThis.litIssuedWarnings ??= new Set();
globalThis.litIssuedWarnings.add(
  "Lit is in dev mode. Not recommended for production! See https://lit.dev/msg/dev-mode for more information.",
);

However, that is far from an ideal solution because the above code would need to be added by every consumer of my package.
Worse, since Lit's warning is emitted in global scope, the consumers have to make sure the above code is added before Lit is imported - which can be challenging in some apps (and the fact that imports are hoisted makes that even trickier)

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions