Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: De-duplicate client console messages #4177

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Jan 14, 2025

Seen in rstudio/bslib#1159. It's possible for bindAll() to be called in a way that we repeatedly issue the same warnings/errors for duplicate or repeated IDs.

This PR updates the shiny-error-console component to de-duplicate message when new messages are added to the console.

Before After
image image

@gadenbuie gadenbuie force-pushed the fix/error-console-dedupe-messages branch from 39c5221 to 6d33a3b Compare January 14, 2025 18:31
@jcheng5
Copy link
Member

jcheng5 commented Jan 21, 2025

I'm fine with this PR's behavior as-is, but if the error console becomes more general in the future we should have a duplicate count like JS consoles have.

@@ -246,7 +270,7 @@ class ShinyErrorConsole extends LitElement {
</svg>
</button>
</div>
<slot class="content"></slot>`;
<slot class="content" @slotchange=${this.dedupeConsoleMessages}></slot>`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that this dedupes after the content has changed, by deduping all of the messages. Could you instead change showShinyClientMessage so that right before performing the append, see if the message already exists? (Or have showShinyClientMessage call a method on ShinyErrorConsole that tracks all of this)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to use a static method ShinyErrorConsole.appendConsoleMessage() to handle adding the message, skipping appending if the message already exists. 48d07c5

@gadenbuie
Copy link
Member Author

gadenbuie commented Jan 21, 2025

but if the error console becomes more general in the future we should have a duplicate count like JS consoles have.

I agree and would like this too. As it is now, however, there's very little added value in showing message counts. It's more likely that we'd emit multiple messages signaling one problem than have multiple problems emit identical messages. The good news is that we still emit all messages to the browser console, where the call stack can help differentiate.

If we make the console more general (which I'd like to see), we'll have to revisit this whole code path and I doubt we'll forget about adding message counts.

@gadenbuie gadenbuie requested a review from cpsievert January 22, 2025 17:26
return msg;
}

static appendConsoleMessage(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why static? Other than that, LGTM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, fixed in 2661a6f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants