Skip to content

Commit 51d5dc4

Browse files
author
Tony Sullivan
authored
Updates an error handler to expect updated @astrojs/lit behavior (#3766)
* fix: don't throw an error when the lit renderer doesn't provide a clientEntrypoint * updating the framework-lit example to match new behavior * fix: updating the playground example to latest lit syntax
1 parent e667477 commit 51d5dc4

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

examples/framework-lit/src/components/Test.js renamed to examples/framework-lit/src/components/calc-add.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { LitElement, html } from 'lit';
22

3-
export const tagName = 'calc-add';
4-
5-
class CalcAdd extends LitElement {
3+
export class CalcAdd extends LitElement {
64
static get properties() {
75
return {
86
num: {
@@ -16,4 +14,4 @@ class CalcAdd extends LitElement {
1614
}
1715
}
1816

19-
customElements.define(tagName, CalcAdd);
17+
customElements.define('calc-add', CalcAdd);

examples/framework-lit/src/components/Counter.js renamed to examples/framework-lit/src/components/my-counter.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { LitElement, html } from 'lit';
22

3-
export const tagName = 'my-counter';
4-
5-
class Counter extends LitElement {
3+
export class MyCounter extends LitElement {
64
static get properties() {
75
return {
86
count: {
@@ -31,4 +29,4 @@ class Counter extends LitElement {
3129
}
3230
}
3331

34-
customElements.define(tagName, Counter);
32+
customElements.define('my-counter', MyCounter);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import Lorem from '../components/Lorem.astro';
3-
import '../components/Test.js';
4-
import '../components/Counter.js';
3+
import { CalcAdd } from '../components/calc-add.js';
4+
import { MyCounter } from '../components/my-counter.js';
55
---
66

77
<!DOCTYPE html>
@@ -12,8 +12,8 @@ import '../components/Counter.js';
1212
</head>
1313
<body>
1414
<h1>Test app</h1>
15-
<my-counter client:load></my-counter>
15+
<MyCounter client:load></MyCounter>
1616
<Lorem />
17-
<calc-add num={33}></calc-add>
17+
<CalcAdd num={33}></CalcAdd>
1818
</body>
1919
</html>

examples/integrations-playground/src/components/Test.js renamed to examples/integrations-playground/src/components/calc-add.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { LitElement, html } from 'lit';
22

3-
export const tagName = 'calc-add';
4-
5-
class CalcAdd extends LitElement {
3+
export class CalcAdd extends LitElement {
64
static get properties() {
75
return {
86
num: {
@@ -16,4 +14,4 @@ class CalcAdd extends LitElement {
1614
}
1715
}
1816

19-
customElements.define(tagName, CalcAdd);
17+
customElements.define('calc-add', CalcAdd);

examples/integrations-playground/src/components/Counter.js renamed to examples/integrations-playground/src/components/my-counter.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { LitElement, html } from 'lit';
22

3-
export const tagName = 'my-counter';
4-
5-
class Counter extends LitElement {
3+
export class MyCounter extends LitElement {
64
static get properties() {
75
return {
86
count: {
@@ -31,4 +29,4 @@ class Counter extends LitElement {
3129
}
3230
}
3331

34-
customElements.define(tagName, Counter);
32+
customElements.define('my-counter', MyCounter);

examples/integrations-playground/src/pages/index.astro

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import Lorem from '../components/Lorem.astro';
33
import Link from '../components/Link.jsx';
44
import SolidCounter from '../components/SolidCounter.jsx';
5-
import '../components/Test.js';
6-
import '../components/Counter.js';
5+
import { CalcAdd } from '../components/calc-add.js';
6+
import { MyCounter } from '../components/my-counter.js';
77
---
88

99
<!DOCTYPE html>
@@ -18,11 +18,11 @@ import '../components/Counter.js';
1818
<strong>Party Mode!</strong>
1919
Colors changing = partytown is enabled
2020
</h2>
21-
<my-counter client:load></my-counter>
21+
<MyCounter client:load></MyCounter>
2222
<SolidCounter client:load></SolidCounter>
2323
<Link to="/foo" text="Go to Page 2" />
2424
<Lorem />
25-
<calc-add num={33}></calc-add>
25+
<CalcAdd num={33}></CalcAdd>
2626
<script type="text/partytown">
2727
// Remove `type="text/partytown"` to see this block the page
2828
// and cause the page to become unresponsive

packages/astro/src/runtime/server/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
358358
}
359359
}
360360

361-
if (renderer && !renderer.clientEntrypoint && metadata.hydrate) {
361+
// HACK! The lit renderer doesn't include a clientEntrypoint for custom elements, allow it
362+
// to render here until we find a better way to recognize when a client entrypoint isn't required.
363+
if (renderer && !renderer.clientEntrypoint && renderer.name !== '@astrojs/lit' && metadata.hydrate) {
362364
throw new Error(
363365
`${metadata.displayName} component has a \`client:${metadata.hydrate}\` directive, but no client entrypoint was provided by ${renderer.name}!`
364366
);

0 commit comments

Comments
 (0)