Skip to content

Commit 650e896

Browse files
authored
Merge pull request #851 from lit/mwc-home-page-perf
2 parents bb96cf6 + e49f0cd commit 650e896

38 files changed

+358
-166
lines changed

Diff for: packages/lit-dev-content/.eleventy.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const luxon = require('luxon');
3333
const crypto = require('crypto');
3434
const pluginRss = require('@11ty/eleventy-plugin-rss');
3535
const litPlugin = require('@lit-labs/eleventy-plugin-lit');
36-
const {componentsToSSR} = require('./src/components/ssr.js');
3736

3837
// Use the same slugify as 11ty for markdownItAnchor. It's similar to Jekyll,
3938
// and preserves the existing URL fragments
@@ -77,9 +76,8 @@ module.exports = function (eleventyConfig) {
7776
'../lit-dev-content/samples/tutorials/**/tutorial.json'
7877
);
7978
eleventyConfig.addWatchTarget('../lit-dev-content/samples/tutorials/**/*.md');
80-
for (const component of componentsToSSR) {
81-
eleventyConfig.addWatchTarget(component);
82-
}
79+
eleventyConfig.addWatchTarget('../lit-dev-content/rollupout/server/*');
80+
eleventyConfig.addWatchTarget('../lit-dev-content/lib/components/ssr.js');
8381

8482
// Placeholder shortcode for TODOs
8583
// Formatting is intentional: outdenting the HTML causes the
@@ -539,12 +537,13 @@ ${content}
539537
return 0;
540538
});
541539
});
542-
let componentModules = componentsToSSR;
540+
541+
let componentModules = ['lib/components/ssr.js'];
543542

544543
// In prod SSR should use the lit templates run through the minifier.
545544
if (!DEV) {
546-
componentModules = componentsToSSR.map((componentPath) =>
547-
componentPath.replace(/^lib\//, 'rollupout/')
545+
componentModules = componentModules.map((componentPath) =>
546+
componentPath.replace('lib/components', 'rollupout/server')
548547
);
549548
}
550549

Diff for: packages/lit-dev-content/package-lock.json

-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/lit-dev-content/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@
199199
"@material/mwc-dialog": "^0.25.1",
200200
"@material/mwc-drawer": "^0.25.1",
201201
"@material/mwc-formfield": "^0.25.1",
202-
"@material/mwc-icon-button": "^0.25.1",
203-
"@material/mwc-icon-button-toggle": "^0.25.1",
204202
"@material/mwc-snackbar": "^0.25.1",
205203
"@material/mwc-textfield": "^0.25.1",
206204
"lit": "^2.1.0",

Diff for: packages/lit-dev-content/rollup.config.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,24 @@ const terserOptions = {
3030

3131
export default [
3232
{
33+
name: 'client',
3334
input: [
3435
// lit-hydrate-support MUST be loaded first to make sure lit hydration
3536
// helpers are bundled before LitElement attempts to use hydration support
3637
'lib/global/lit-hydrate-support.js',
3738
'lib/components/copy-button.js',
38-
'lib/components/lazy-svg.js',
3939
'lib/components/litdev-aside.js',
4040
'lib/components/litdev-banner.js',
41-
'lib/components/litdev-version-selector.js',
4241
'lib/components/litdev-drawer.js',
4342
'lib/components/litdev-example.js',
4443
'lib/components/ts-js.js',
45-
'lib/components/litdev-search.js',
4644
'lib/components/litdev-switchable-sample.js',
4745
'lib/components/litdev-tutorial.js',
48-
'lib/components/litdev-tutorial-card.js',
4946
'lib/components/playground-elements.js',
5047
'lib/components/resize-bar.js',
5148
'lib/components/litdev-playground-page.js',
5249
'lib/github/github-signin-receiver-page.js',
5350
'lib/global/hydrate-common-components.js',
54-
'lib/global/mobile-nav.js',
5551
'lib/pages/docs.js',
5652
'lib/pages/home.js',
5753
'lib/pages/home-components.js',
@@ -101,6 +97,27 @@ export default [
10197
}),
10298
],
10399
},
100+
{
101+
name: 'SSR',
102+
input: [
103+
// A separate bundle is made for the server so that we do not modify the
104+
// client module graph just to SSR a component.
105+
'lib/components/ssr.js',
106+
],
107+
output: {
108+
dir: 'rollupout/server',
109+
format: 'esm',
110+
},
111+
plugins: [
112+
resolve(),
113+
minifyHTML(),
114+
terser(terserOptions),
115+
summary({
116+
// Already minified.
117+
showMinifiedSize: false,
118+
}),
119+
],
120+
},
104121

105122
// These scripts are inlined and must run before first render because they set
106123
// global CSS classes/attributes that would otherwise cause restyle/relayout.

Diff for: packages/lit-dev-content/site/_includes/default.html

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@
88
<meta name="description" content="Simple. Fast. Web Components.">
99
<link rel="icon" href="{{ site.baseurl }}/images/flame-favicon.svg">
1010
<link rel="mask-icon" href="{{ site.baseurl }}/images/flame-favicon.svg" color="#324fff">
11-
<link rel="modulepreload" href="{{ site.baseurl }}/js/global/lit-hydrate-support.js">
11+
<link rel="modulepreload" href="{{ site.baseurl }}/js/tslib.js">
12+
{% if not env.DEV %}
13+
<link rel="modulepreload" href="{{ site.baseurl }}/js/lit.js">
14+
{% endif %}
15+
<link rel="modulepreload" href="{{ site.baseurl }}/js/global/hydrate-common-components.js">
1216

1317
{% inlinecss "global.css" %}
1418

1519
{% inlinecss "mods.css" %}
1620
{% inlinejs "global/apply-mods.js" %}
1721
{% inlinejs "global/initialize-typescript-attribute.js" %}
1822
{% inlinejs "global/mobile-drawer.js" %}
19-
<script type="module" src="{{ site.baseurl }}/js/global/lit-hydrate-support.js"></script>
23+
{% if env.DEV %}
24+
<script type="module" src="{{ site.baseurl }}/js/global/lit-hydrate-support.js"></script>
25+
{% else %}
26+
<!-- Loads lit-hydration since we manually chunk this -->
27+
<script type="module" href="{{ site.baseurl }}/js/lit.js"></script>
28+
{% endif %}
2029
{% inlinejs "global/dsd-polyfill.js" %}
2130

2231
{% if selectedVersion !== latestVersion %}
@@ -26,7 +35,6 @@
2635

2736
<script type="module" src="{{ site.baseurl }}/js/global/hydrate-common-components.js"></script>
2837

29-
<script type="module" src="{{ site.baseurl }}/js/global/mobile-nav.js"></script>
3038
{% if not noaside %}
3139
<script type="module" src="{{ site.baseurl }}/js/components/litdev-aside.js"></script>
3240
{% endif %}
@@ -35,8 +43,6 @@
3543
isn't yet supported in Firefox or Safari. -->
3644
{% if not env.DEV %}
3745
<script type="module" src="{{ site.baseurl }}/js/tslib.js"></script>
38-
<script type="module" src="{{ site.baseurl }}/js/mwc-base.js"></script>
39-
<script type="module" src="{{ site.baseurl }}/js/mwc-icon-button.js"></script>
4046
{% endif %}
4147

4248
<link rel="preconnect" href="https://fonts.gstatic.com">

Diff for: packages/lit-dev-content/site/_includes/header.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
{% include 'site-nav.html' %}
99
</ol>
1010

11-
<mwc-icon-button
11+
<litdev-ripple-icon-button
1212
id="mobileMenuButton"
1313
label="Open menu"
1414
>
1515
<svg height="24" width="24" fill="currentcolor">
1616
<path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" />
1717
</svg>
18-
</mwc-icon-button>
18+
</litdev-ripple-icon-button>
1919
</nav>
2020
</header>

Diff for: packages/lit-dev-content/site/css/header.css

-5
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,4 @@ header > nav {
8282
header {
8383
padding: 0 0.5em;
8484
}
85-
86-
/* Eliminate sizing FOUC before menu button upgrades. */
87-
header mwc-icon-button:not(:defined) {
88-
padding: 12px;
89-
}
9085
}

Diff for: packages/lit-dev-content/site/css/tutorial.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ litdev-tutorial {
102102
align-items: center;
103103
}
104104

105-
#tutorialHeader .lhs mwc-icon-button {
105+
#tutorialHeader .lhs litdev-ripple-icon-button {
106106
margin-inline-end: .5em;
107107
}
108108

Diff for: packages/lit-dev-content/src/components/copy-button.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {LitElement, html, css} from 'lit';
88
import {property} from 'lit/decorators.js';
99
import {copyIcon} from '../icons/copy-icon.js';
1010

11-
import '@material/mwc-icon-button';
11+
import './litdev-ripple-icon-button.js';
1212

1313
/**
1414
* A button that copies some text when clicked.
@@ -25,13 +25,12 @@ export class CopyButton extends LitElement {
2525
text?: string;
2626

2727
render() {
28-
return html`<mwc-icon-button
29-
outlined
28+
return html`<litdev-ripple-icon-button
3029
@click=${this._click}
31-
aria-label="Copy to clipboard"
30+
label="Copy to clipboard"
3231
>
3332
${copyIcon}
34-
</mwc-icon-button>`;
33+
</litdev-ripple-icon-button>`;
3534
}
3635

3736
private _click() {

Diff for: packages/lit-dev-content/src/components/lazy-svg.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import {css, html, LitElement, nothing, PropertyValues} from 'lit';
88
import {customElement, property, state, query} from 'lit/decorators.js';
9+
import {onIdle} from '../util/hydration-helpers';
910

1011
/**
1112
* Strategies for loading the SVG. idle, waits for the idle callback, eager
@@ -100,7 +101,7 @@ export default class LazySvg extends LitElement {
100101
updated(changed: PropertyValues<this>) {
101102
if (changed.has('loading')) {
102103
if (this.loading === 'idle') {
103-
this._idleLoad();
104+
onIdle(this._onIdle);
104105
} else if (this.loading === 'visible') {
105106
// Must happen in `updated` because in non-SSR the DOM is not ready
106107
this._visibleLoad();
@@ -110,16 +111,9 @@ export default class LazySvg extends LitElement {
110111
super.updated(changed);
111112
}
112113

113-
private _idleLoad() {
114-
if ('requestIdleCallback' in window) {
115-
(window as any).requestIdleCallback(() => (this._shouldLoad = true));
116-
} else {
117-
// Safari doesn't have idle callback so just wait 200ms
118-
setTimeout(() => {
119-
this._shouldLoad = true;
120-
}, 200);
121-
}
122-
}
114+
private _onIdle = () => {
115+
this._shouldLoad = true;
116+
};
123117

124118
private _visibleLoad() {
125119
const observer = new IntersectionObserver(

Diff for: packages/lit-dev-content/src/components/litdev-drawer.ts

+40-38
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,40 @@
1414

1515
import {LitElement, html, css} from 'lit';
1616
import {property, customElement} from 'lit/decorators.js';
17-
import '@material/mwc-icon-button-toggle';
17+
import './litdev-ripple-icon-button.js';
18+
19+
// https://material.io/resources/icons/?icon=close
20+
const closeIcon = html` <svg
21+
width="24"
22+
height="24"
23+
viewBox="0 0 24 24"
24+
fill="currentcolor"
25+
>
26+
<path
27+
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
28+
/>
29+
</svg>`;
30+
31+
// Source: https://material.io/resources/icons/?icon=menu_book
32+
const bookIcon = html` <svg
33+
width="24"
34+
height="24"
35+
viewBox="0 0 24 24"
36+
fill="currentcolor"
37+
>
38+
<path
39+
d="M21,5c-1.11-0.35-2.33-0.5-3.5-0.5c-1.95,0-4.05,0.4-5.5,1.5c-1.45-1.1-3.55-1.5-5.5-1.5S2.45,4.9,1,6v14.65 c0,0.25,0.25,0.5,0.5,0.5c0.1,0,0.15-0.05,0.25-0.05C3.1,20.45,5.05,20,6.5,20c1.95,0,4.05,0.4,5.5,1.5c1.35-0.85,3.8-1.5,5.5-1.5 c1.65,0,3.35,0.3,4.75,1.05c0.1,0.05,0.15,0.05,0.25,0.05c0.25,0,0.5-0.25,0.5-0.5V6C22.4,5.55,21.75,5.25,21,5z M21,18.5 c-1.1-0.35-2.3-0.5-3.5-0.5c-1.7,0-4.15,0.65-5.5,1.5V8c1.35-0.85,3.8-1.5,5.5-1.5c1.2,0,2.4,0.15,3.5,0.5V18.5z"
40+
/>
41+
<path
42+
d="M17.5,10.5c0.88,0,1.73,0.09,2.5,0.26V9.24C19.21,9.09,18.36,9,17.5,9c-1.7,0-3.24,0.29-4.5,0.83v1.66 C14.13,10.85,15.7,10.5,17.5,10.5z"
43+
/>
44+
<path
45+
d="M13,12.49v1.66c1.13-0.64,2.7-0.99,4.5-0.99c0.88,0,1.73,0.09,2.5,0.26V11.9c-0.79-0.15-1.64-0.24-2.5-0.24 C15.8,11.66,14.26,11.96,13,12.49z"
46+
/>
47+
<path
48+
d="M17.5,14.33c-1.7,0-3.24,0.29-4.5,0.83v1.66c1.13-0.64,2.7-0.99,4.5-0.99c0.88,0,1.73,0.09,2.5,0.26v-1.52 C19.21,14.41,18.36,14.33,17.5,14.33z"
49+
/>
50+
</svg>`;
1851

1952
/**
2053
* A drawer that expands and collapses.
@@ -66,6 +99,9 @@ export class LitDevDrawer extends LitElement {
6699
}
67100
68101
#openCloseButton {
102+
width: 37px;
103+
height: 37px;
104+
padding: 4px;
69105
position: absolute;
70106
/* Align close icon to content, accounting for larger touch target */
71107
right: 0;
@@ -114,47 +150,13 @@ export class LitDevDrawer extends LitElement {
114150
<div id="header" part="header">
115151
<slot name="header"></slot>
116152
117-
<mwc-icon-button-toggle
153+
<litdev-ripple-icon-button
118154
id="openCloseButton"
119155
aria-label="Open or close examples drawer"
120-
.on=${!this.open}
121156
@click=${this._onClickToggleButton}
122157
>
123-
<!-- Source: https://material.io/resources/icons/?icon=close --->
124-
<svg
125-
slot="offIcon"
126-
width="24"
127-
height="24"
128-
viewBox="0 0 24 24"
129-
fill="currentcolor"
130-
>
131-
<path
132-
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
133-
/>
134-
</svg>
135-
136-
<!-- Source: https://material.io/resources/icons/?icon=menu_book --->
137-
<svg
138-
slot="onIcon"
139-
width="24"
140-
height="24"
141-
viewBox="0 0 24 24"
142-
fill="currentcolor"
143-
>
144-
<path
145-
d="M21,5c-1.11-0.35-2.33-0.5-3.5-0.5c-1.95,0-4.05,0.4-5.5,1.5c-1.45-1.1-3.55-1.5-5.5-1.5S2.45,4.9,1,6v14.65 c0,0.25,0.25,0.5,0.5,0.5c0.1,0,0.15-0.05,0.25-0.05C3.1,20.45,5.05,20,6.5,20c1.95,0,4.05,0.4,5.5,1.5c1.35-0.85,3.8-1.5,5.5-1.5 c1.65,0,3.35,0.3,4.75,1.05c0.1,0.05,0.15,0.05,0.25,0.05c0.25,0,0.5-0.25,0.5-0.5V6C22.4,5.55,21.75,5.25,21,5z M21,18.5 c-1.1-0.35-2.3-0.5-3.5-0.5c-1.7,0-4.15,0.65-5.5,1.5V8c1.35-0.85,3.8-1.5,5.5-1.5c1.2,0,2.4,0.15,3.5,0.5V18.5z"
146-
/>
147-
<path
148-
d="M17.5,10.5c0.88,0,1.73,0.09,2.5,0.26V9.24C19.21,9.09,18.36,9,17.5,9c-1.7,0-3.24,0.29-4.5,0.83v1.66 C14.13,10.85,15.7,10.5,17.5,10.5z"
149-
/>
150-
<path
151-
d="M13,12.49v1.66c1.13-0.64,2.7-0.99,4.5-0.99c0.88,0,1.73,0.09,2.5,0.26V11.9c-0.79-0.15-1.64-0.24-2.5-0.24 C15.8,11.66,14.26,11.96,13,12.49z"
152-
/>
153-
<path
154-
d="M17.5,14.33c-1.7,0-3.24,0.29-4.5,0.83v1.66c1.13-0.64,2.7-0.99,4.5-0.99c0.88,0,1.73,0.09,2.5,0.26v-1.52 C19.21,14.41,18.36,14.33,17.5,14.33z"
155-
/>
156-
</svg>
157-
</mwc-icon-button-toggle>
158+
${this.open ? closeIcon : bookIcon}
159+
</litdev-ripple-icon-button>
158160
</div>
159161
160162
<div id="content">

0 commit comments

Comments
 (0)