Migration: 2021/11/8

Section titled Migration: 2021/11/8

As of Nov 8, 2021, Spectrum Web Components will upgrade to Lit 2.0 and will cease depending on separate lit-element and lit-html modules internally. This will only require action from you if:

  1. You embed icons as template literals (<sp-icon>${RedoIcon()}</sp-icon>) in a project that uses lit-html@1.x or lit-element@2.x.
  2. You wish to combine Spectrum component versions from pre-Lit 2.0 with those from post-Lit 2.0.

Otherwise, you can safely upgrade to the latest versions of Spectrum Web Components, shrinking your bundle size and improving your project's performance.

If you embed icons as template literals, please reference the icon migration guide below while upgrading.

Combining components based on Lit 2.0 with older versions of components may increase your bundle size, since both versions of the underlying LitElement libraries will be required, while the practice of elements registering sub-elements increasing the possibility of JS errors from attempting to register the same tab name more than once. Because of this, we recommend simultaneously upgrading all components in your project to at least the versions listed here:

Package Versions
Package Version
@spectrum-web-components/accordion 0.6.0
@spectrum-web-components/action-bar 0.4.0
@spectrum-web-components/action-button 0.7.0
@spectrum-web-components/action-group 0.6.0
@spectrum-web-components/action-menu 0.13.0
@spectrum-web-components/asset 0.6.0
@spectrum-web-components/avatar 0.9.0
@spectrum-web-components/banner 0.7.0
@spectrum-web-components/base 0.5.0
@spectrum-web-components/bundle 0.23.0
@spectrum-web-components/button-group 0.8.0
@spectrum-web-components/button 0.16.0
@spectrum-web-components/card 0.10.0
@spectrum-web-components/checkbox 0.12.0
@spectrum-web-components/coachmark 0.8.0
@spectrum-web-components/color-area 0.4.0
@spectrum-web-components/color-handle 0.3.0
@spectrum-web-components/color-loupe 0.3.0
@spectrum-web-components/color-slider 0.3.0
@spectrum-web-components/color-wheel 0.3.0
@spectrum-web-components/dialog 0.8.0
@spectrum-web-components/divider 0.4.0
@spectrum-web-components/dropzone 0.9.0
@spectrum-web-components/field-group 0.5.0
@spectrum-web-components/field-label 0.7.0
@spectrum-web-components/icon 0.11.0
@spectrum-web-components/icons-ui 0.8.0
@spectrum-web-components/icons-workflow 0.8.0
@spectrum-web-components/icons 0.8.0
@spectrum-web-components/iconset 0.6.0
@spectrum-web-components/illustrated-message 0.8.0
@spectrum-web-components/link 0.11.0
@spectrum-web-components/menu 0.11.0
@spectrum-web-components/meter 0.6.0
@spectrum-web-components/modal 0.5.0
@spectrum-web-components/number-field 0.3.0
@spectrum-web-components/overlay 0.13.0
@spectrum-web-components/picker 0.9.0
@spectrum-web-components/popover 0.11.0
@spectrum-web-components/progress-bar 0.5.0
@spectrum-web-components/progress-circle 0.4.0
@spectrum-web-components/radio 0.9.0
@spectrum-web-components/search 0.10.0
@spectrum-web-components/shared 0.13.0
@spectrum-web-components/sidenav 0.12.0
@spectrum-web-components/slider 0.12.0
@spectrum-web-components/split-view 0.4.0
@spectrum-web-components/status-light 0.10.0
@spectrum-web-components/styles 0.11.0
@spectrum-web-components/switch 0.9.0
@spectrum-web-components/tabs 0.8.0
@spectrum-web-components/tags 0.8.0
@spectrum-web-components/textfield 0.10.0
@spectrum-web-components/theme 0.9.0
@spectrum-web-components/thumbnail 0.4.0
@spectrum-web-components/toast 0.10.0
@spectrum-web-components/tooltip 0.10.0
@spectrum-web-components/top-nav 0.5.0
@spectrum-web-components/tray 0.2.0
@spectrum-web-components/underlay 0.8.0
@spectrum-web-components/story-decorator 0.4.0
@spectrum-web-components/vrt-compare 0.1.0

Using lit@2.0 inside of lit-html and/or LitElement

Section titled Using

If you use lit-html@1.x or lit-element@2.x, embed icons as template literals, and plan to use the latest Spectrum Web Components without updating your project to Lit 2.0, you'll need to adjust icon usage to avoid templating errors.

Here's an example illustrating that combination of factors:

import { LitElement } from 'lit-element';
import { html } from 'lit-html';
import '@spectrum-web-components/icon/sp-icon.js';
import { RedoIcon } from '@spectrum-web-components/icons-workflow';

export class ElementWithicon extends LitElement {
    render() {
        return html`
            // ...
            <sp-icon>${RedoIcon()}</sp-icon>
            // ...
        `;
    }
}

Here, RedoIcon() returns a value built with the html dependency of @spectrum-web-components/icons-workflow. After this update, that value will no longer be compatible with the html tag in the render() function here, which is still built with the lit-html module.

There are two ways to correct this. We recommend replacing template-literal icons with icon elements, resulting in better performance and decoupled dependencies:

import { LitElement } from 'lit-element';
import { html } from 'lit-html';
import '@spectrum-web-components/icons-workflow/icons/sp-icon-redo.js';

export class ElementWithicon extends LitElement {
    render() {
        return html`
            // ...
            <sp-icon-redo></sp-icon-redo>
            // ...
        `;
    }
}

Alternatively, provide your local value for html to the icon templates via setCustomTemplateLiteralTag:

import { html } from 'lit-html';
import {
    RedoIcon,
    setCustomTemplateLiteralTag,
} from '@spectrum-web-components/icons-workflow';

setCustomTemplateLiteralTag(html);

Javascript re-exports

Section titled Javascript re-exports

Previously, @spectrum-web-components/base re-exported a number of things from the lit-element and lit-html packages like so:

// @spectrum-web-components/base
export * from 'lit-element';
export { nothing } from 'lit-html';
export { ifDefined } from 'lit-html/directives/if-defined.js';
export { repeat } from 'lit-html/directives/repeat.js';
export { classMap } from 'lit-html/directives/class-map.js';
export { styleMap } from 'lit-html/directives/style-map.js';
export { until } from 'lit-html/directives/until.js';
export { live } from 'lit-html/directives/live.js';

With the move the lit greater care is being taken to ensure that importing JS from this package delivers only what you might need in your application, so we have updated the entrypoints on this package to the following: @spectrum-web-components/base, @spectrum-web-components/base/decorators.js, @spectrum-web-components/base/html.js, and @spectrum-web-components/base/directives.js. These files will re-export lit values as follows:

// @spectrum-web-components/base
export * from 'lit';
// @spectrum-web-components/base/decorators.js
export * from 'lit/decorators.js';
// @spectrum-web-components/base/html.js
export { nothing, render } from 'lit/html.js';
// @spectrum-web-components/base/directives.js
export { ifDefined } from 'lit/directives/if-defined.js';
export { repeat } from 'lit/directives/repeat.js';
export { classMap } from 'lit/directives/class-map.js';
export type { ClassInfo } from 'lit/directives/class-map.js';
export { styleMap } from 'lit/directives/style-map.js';
export type { StyleInfo } from 'lit/directives/style-map.js';
export { until } from 'lit/directives/until.js';
export { live } from 'lit/directives/live.js';

Additional lit exports can be acquired directly from the lit package.

With Lit 2.0 bringing same-document library-version flexibility, re-exporting from shared base libraries is less critical. We may eventually recommend direct imports from lit as the preferred path towards acquiring these values.