Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: De-duplicate client console messages
Browse files Browse the repository at this point in the history
gadenbuie committed Jan 14, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 79f42f5 commit 5ddbe65
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion srcts/src/components/errorConsole.ts
Original file line number Diff line number Diff line change
@@ -200,6 +200,30 @@ class ShinyErrorConsole extends LitElement {
});
}

private dedupeConsoleMessages(e: Event): void {
const slot = e.target as HTMLSlotElement;
const nodes = slot.assignedNodes();

const uniqueMessages = new Set();

const nodeKey = (node: Element) => {
const headline = node.getAttribute("headline") || "";
const message = node.getAttribute("message") || "";
return `${headline}::${message}`;
};

// Keep only one copy of each unique message
nodes.forEach((node) => {
if (
node instanceof HTMLElement &&
node.tagName.toLowerCase() === "shiny-error-message"
) {
const key = nodeKey(node);
uniqueMessages.has(key) ? node.remove() : uniqueMessages.add(key);
}
});
}

render() {
return html` <div class="header">
<span class="title"> Shiny Client Errors </span>
@@ -246,7 +270,7 @@ class ShinyErrorConsole extends LitElement {
</svg>
</button>
</div>
<slot class="content"></slot>`;
<slot class="content" @slotchange=${this.dedupeConsoleMessages}></slot>`;
}
}

0 comments on commit 5ddbe65

Please sign in to comment.