Skip to content

Commit

Permalink
Give a clearer error message when rendering into null/undefined (#2661)
Browse files Browse the repository at this point in the history
  • Loading branch information
rictic committed Mar 25, 2022
1 parent 1d51ed8 commit 9a3a38c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/tidy-lies-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'lit-html': patch
'lit': patch
---

Give a clearer error message when rendering into null/undefined
7 changes: 7 additions & 0 deletions packages/lit-html/src/lit-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,13 @@ export const render = (
container: HTMLElement | DocumentFragment,
options?: RenderOptions
): RootPart => {
if (DEV_MODE && container == null) {
// Give a clearer error message than
// Uncaught TypeError: Cannot read properties of null (reading
// '_$litPart$')
// which reads like an internal Lit error.
throw new TypeError(`The container to render into may not be ${container}`);
}
const renderId = DEV_MODE ? debugLogRenderId++ : 0;
const partOwnerNode = options?.renderBefore ?? container;
// This property needs to remain unminified.
Expand Down

0 comments on commit 9a3a38c

Please sign in to comment.