Skip to content

Commit

Permalink
Handle empty node list (#241)
Browse files Browse the repository at this point in the history
Implementation of the fix suggested in issue #230

'Uncaught TypeError: node.getAttribute is not a function when passed an empty node list'
  • Loading branch information
gabalis authored Jan 8, 2024
1 parent 3ce10cc commit 37c19a8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export function cancel(node?: HTMLElement): void {
export function render(nodes: HTMLElement | HTMLElement[] | NodeList, locale?: string, opts?: Opts) {
// by .length
// @ts-ignore
const nodeList: HTMLElement[] = nodes.length ? nodes : [nodes];
// supports empty list of nodes
const nodeList: HTMLElement[] = NodeList.prototype.isPrototypeOf(nodes) ? nodes : [nodes];

nodeList.forEach((node: HTMLElement) => {
run(node, getDateAttribute(node), getLocale(locale), opts || {});
Expand Down

0 comments on commit 37c19a8

Please sign in to comment.