Skip to content

Commit 6c7a55f

Browse files
aomarksjustinfagnani
authored andcommitted
Upgrade to new Lit SSR with automatic DOM shimming
1 parent 4bfc9e3 commit 6c7a55f

File tree

12 files changed

+221
-68
lines changed

12 files changed

+221
-68
lines changed

package-lock.json

Lines changed: 186 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/catalog-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"firebase-admin": "^11.0.0",
113113
"graphql-helix": "^1.13.0",
114114
"koa-bodyparser": "^4.3.0",
115-
"lit": "^2.4.0",
115+
"lit": "^2.6.0",
116116
"natural": "^5.2.3",
117117
"semver": "^7.3.7"
118118
}

packages/site-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"@urql/core": "^3.0.4",
9090
"@webcomponents/catalog-api": "^0.0.0",
9191
"graphql": "^16.6.0",
92-
"lit": "^2.3.1",
92+
"lit": "^2.6.0",
9393
"lit-analyzer": "^1.2.1"
9494
}
9595
}

packages/site-client/src/components/wco-catalog-search.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export class WCOCatalogSearch extends LitElement {
6767
protected firstUpdated() {
6868
// TODO (justinfagnani): we may want to use a router (and write the search
6969
// to the URL) but this is easy for now.
70-
const urlQuery = new URLSearchParams(window.location.search).get('query');
70+
const urlQuery = new URLSearchParams(globalThis.location.search).get(
71+
'query'
72+
);
7173
if (urlQuery) {
7274
this._search.value = urlQuery;
7375
this._onChange();

packages/site-client/src/components/wco-top-bar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {html, css, LitElement} from 'lit';
88
import {customElement} from 'lit/decorators.js';
99
import {classMap} from 'lit/directives/class-map.js';
1010

11-
const pathStartsWith = (s: string) => window.location.pathname.startsWith(s);
11+
const pathStartsWith = (s: string) =>
12+
globalThis.location.pathname.startsWith(s);
1213

1314
@customElement('wco-top-bar')
1415
export class WCOTopBar extends LitElement {

packages/site-client/src/entrypoints/element-hydrate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {hydrate} from 'lit/experimental-hydrate.js';
88
import {renderElementPage} from './element.js';
99

1010
const data = (
11-
window as unknown as {__ssrData: Parameters<typeof renderElementPage>}
11+
globalThis as unknown as {__ssrData: Parameters<typeof renderElementPage>}
1212
).__ssrData;
1313

1414
// We need to hydrate the whole page to remove any defer-hydration attributes.

packages/site-content/site/_includes/layouts/docs.11ty.cjs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ module.exports = {
99
const {renderPage, html, unsafeHTML} = await import(
1010
'../../../templates/lib/base.js'
1111
);
12-
await import('@webcomponents/internal-site-client/lib/components/wco-nav-page.js');
12+
await import(
13+
'@webcomponents/internal-site-client/lib/components/wco-nav-page.js'
14+
);
1315

14-
// URL isn't exactly a Location, but it's close enough for read-only uses
15-
window.location = new URL('http://localhost:5450/docs/');
16+
// Set location because wco-nav-bar reads pathname from it. URL isn't
17+
// exactly a Location, but it's close enough for read-only uses
18+
globalThis.location = new URL('http://localhost:5450/docs/');
1619

1720
const navigationEntries = this.eleventyNavigation(data.collections.all);
1821

@@ -24,11 +27,10 @@ module.exports = {
2427
return [
2528
...renderPage({
2629
...data,
27-
content: html`
28-
<wco-nav-page>
29-
<div slot="outline">${unsafeHTML(navigationHTML)}</div>
30-
${unsafeHTML(data.content)}
31-
</wco-nav-page>`,
30+
content: html`<wco-nav-page>
31+
<div slot="outline">${unsafeHTML(navigationHTML)}</div>
32+
${unsafeHTML(data.content)}
33+
</wco-nav-page>`,
3234
}),
3335
].join('');
3436
},

packages/site-content/site/_includes/layouts/home.11ty.cjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ module.exports = {
99
const {renderPage, html, unsafeHTML} = await import(
1010
'../../../templates/lib/base.js'
1111
);
12-
await import('@webcomponents/internal-site-client/lib/components/wco-home-page.js');
12+
await import(
13+
'@webcomponents/internal-site-client/lib/components/wco-home-page.js'
14+
);
15+
// Set location because wco-nav-bar reads pathname from it. URL isn't
16+
// exactly a Location, but it's close enough for read-only uses
17+
globalThis.location = new URL('http://localhost:5450/');
1318
return [
1419
...renderPage({
1520
...data,
16-
content: html`<wco-home-page>${unsafeHTML(data.content)}</wco-home-page>`,
21+
content: html`<wco-home-page
22+
>${unsafeHTML(data.content)}</wco-home-page
23+
>`,
1724
}),
1825
].join('');
1926
},

packages/site-content/templates/src/base.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
*/
66

77
// This must be imported before lit
8-
import {
9-
render,
10-
RenderInfo,
11-
} from '@lit-labs/ssr/lib/render-with-global-dom-shim.js';
8+
import {render, RenderInfo} from '@lit-labs/ssr';
129

1310
import type {TemplateResult} from 'lit';
1411
import type {DirectiveResult} from 'lit/directive.js';

packages/site-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"@apollo/client": "^3.7.0",
9797
"@koa/cors": "^4.0.0",
9898
"@koa/router": "^12.0.0",
99-
"@lit-labs/ssr": "^2.2.3",
99+
"@lit-labs/ssr": "^3.0.0",
100100
"@types/koa": "^2.13.5",
101101
"@types/koa__cors": "^3.3.0",
102102
"@types/koa__router": "^12.0.0",

0 commit comments

Comments
 (0)