Lit 3.x (lit@3, lit-element@4, lit-html@3)
Lit 3.0.0 was released alongside[email protected] and [email protected]. The lit package is the recommended entry point for all new projects.
Breaking changes in Lit 3.0
IE11 support dropped
Lit 3 no longer supports Internet Explorer 11. The polyfill configuration and IE11-specific code paths have been removed. If you need to support older browsers, stay on Lit 2.Generated accessors now wrap user-defined accessors
In Lit 3, the generated accessor for a reactive property now wraps any user-defined accessor and automatically callsthis.requestUpdate() in the setter. In previous versions, if you defined your own accessor for a @property-decorated field, you had to call requestUpdate() yourself.
Users who set noAccessor: true must still call this.requestUpdate() themselves:
@queryAssignedNodes selector argument removed
The deprecated selector argument to@queryAssignedNodes has been removed. Migrate to @queryAssignedElements if you need selector filtering:
Experimental hydrate modules removed
Thelit-html/experimental-hydrate.js and lit-element/experimental-hydrate-support.js modules have been removed. Use @lit-labs/ssr-client instead:
renderRoot type change
The type ofReactiveElement.renderRoot and the return type of createRenderRoot() have changed from Element | ShadowRoot to HTMLElement | DocumentFragment to match lit-html’s render() method.
Lit 1 → 2 migration warnings removed
The dev-mode warnings that guided migration from Lit 1 to Lit 2 have been removed in Lit 3.SVG templates use replaceWith()
Lit now usesreplaceWith() for SVG template rendering. This is a standards-compliant change that should be transparent to most users.
Boolean attribute parts use toggleAttribute()
Boolean attribute bindings (?disabled=${...}) now use toggleAttribute() internally. This is a standards-compliant change that should not affect behavior.
Minor additions in Lit 3.0
PropertyValues.get()now returnsT | undefined(previouslyT). Update code that assumed the return type was neverundefined.@query()decorated fields now allownullin their type.- Decorators work with the
accessorkeyword whenexperimentalDecoratorsistrue. - Dev mode warns when
performUpdate()is overridden with anasyncfunction.
Lit 3.1 additions
- Accessing a cached
@queryfield before the first update no longer permanently cachesnull. A dev-mode warning is issued instead. - Two new types exported:
UncompiledTemplateResultandMaybeCompiledTemplateResult.
Lit 3.2 additions
- MathML support via the
mathmltemplate tag.
Lit 3.3 additions
- New
useDefaultproperty option: when set, the initial default value is not considered a change and does not reflect. When the attribute is removed, the default value is restored. ClassInfotype is now mutable.
Lit 2.x (lit@2, lit-element@3, lit-html@2)
Lit 2 introduced the unifiedlit package and renamed several APIs from Lit 1. If you are upgrading from [email protected] or [email protected], start here.
Upgrading packages and import paths
The recommended entry point changed fromlit-element to lit:
package.json:
@internalProperty renamed to @state
Decorators moved out of lit-element
Decorators are no longer exported from thelit-element module. Import them from lit/decorators.js or individual files:
UpdatingElement renamed to ReactiveElement
UpdatingElement from the lit-element package has been moved to @lit/reactive-element and renamed to ReactiveElement. If you subclassed UpdatingElement directly, update the import:
_getUpdateComplete renamed to getUpdateComplete
requestUpdate no longer returns a Promise
requestUpdate() previously returned a Promise. In Lit 2, it returns void. Await this.updateComplete instead:
requestUpdateInternal removed
requestUpdateInternal has been removed. Use requestUpdate directly.
LitElement.adoptStyles removed
LitElement.adoptStyles() has been removed. Styling is now adopted in createRenderRoot(). If you overrode adoptStyles to customize style adoption, override createRenderRoot() instead.
LitElement.getStyles renamed to finalizeStyles
static render removed
The staticrender method on LitElement has been removed.
createRenderRoot called before first update
In Lit 2,createRenderRoot() is called just before the first update rather than in the constructor. Do not assume this.renderRoot exists before hasUpdated is true.
ReactiveElement.initialize removed
Theinitialize method has been removed. The work it performed is now done in the element constructor.
lit-html 2.x breaking changes
templateFactory option removed
ThetemplateFactory option of RenderOptions has been removed.
TemplateProcessor removed
TemplateProcessor has been removed.
NodePart renamed to ChildPart
NodePart has been renamed to ChildPart. Associated names like PartType.Node have been renamed to PartType.CHILD.
Part constructors no longer exported
Part constructors (ChildPart, AttributePart, etc.) are now interface-only exports. Use helpers from lit-html/directive-helpers.js to construct parts in custom directives.
render() appends instead of replacing
render() no longer clears the container before rendering. It now appends to the container by default.
Expressions in comments no longer rendered
Expressions inside HTML comments (<!-- ${value} -->) are no longer rendered or updated.
Arrays in attribute bindings
Arrays passed to attribute bindings are no longer handled specially. They render using their default.toString() representation:
Directive and part APIs changed
The directive and part APIs are significantly different in lit-html 2. TheDirective base class and directive() factory function are now exported from lit-html/directive.js. See the Upgrade Guide for full details on updating custom directive implementations.
eventContext renamed to host
TheeventContext render option has been renamed to host.
Symbols in bindings throw
Symbols are no longer silently converted to strings in bindings. Passing a Symbol to a text or attribute binding now throws an exception.Upgrade checklist
Update import paths
Replace
from 'lit-element' with from 'lit'. Move decorator imports to from 'lit/decorators.js'.Update @queryAssignedNodes usage
Replace any
@queryAssignedNodes calls with selector arguments with @queryAssignedElements.Update hydration imports (Lit 3 only)
Replace
lit-element/experimental-hydrate-support.js with @lit-labs/ssr-client/lit-element-hydrate-support.js.Run TypeScript
Fix any type errors surfaced by the updated type definitions, particularly around
renderRoot, updateComplete, and removed APIs.