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

Avoid re-registering bslib components and globals #1045

Merged
merged 5 commits into from
Apr 23, 2024
Merged

Conversation

gadenbuie
Copy link
Member

Fixes #1044

Avoids redefining bslib-provided custom elements or web components (e.g. bslib-tooltip, bslib-popover) as well as globally-registered classes (bslib.Sidebar and bslib.Card).

In both cases a console error message is provided:

[bslib] Global window.bslib.Sidebar was already defined, using previous definition.
[bslib] Custom element bslib-tooltip was already defined, using previous definition.

@@ -528,7 +528,5 @@ class SidebarInputBinding extends InputBinding {
}

registerBinding(SidebarInputBinding, "sidebar");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd be curious to know how registerBinding() handles this (i.e., does the last one win)? Seems like it'd be wise to match whatever it does?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would we want adding bslib::value_box() to a Quarto dashboard to use Quarto's components -- that they test against and expect to work -- or to use bslib's component js instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, good point, makes sense for the 1st one to win then. But also, if the last one wins for registerBinding(), wouldn't the binding be using the wrong Sidebar (i.e., we should maybe update registerBinding() to do something similar to registerBslibGlobal())?

Copy link
Member Author

Choose a reason for hiding this comment

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

registerBinding() is basically a safe call to BindingsRegistry.register() in shiny. "registering" a binding just adds it to the end of an array. The .getBindings() method breaks ties using the priority propery, followed by most-recently-registered.

Anyway, you're pointing out that this isn't an unambiguous or complete fix, and I agree. This PR at least gets us out of the position of breaking Dashboards. We'll have to do some thinking in the future

@gadenbuie gadenbuie merged commit 5046bbd into main Apr 23, 2024
13 checks passed
@gadenbuie gadenbuie deleted the gadenbuie/issue1044 branch April 23, 2024 19:23
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.

Using a bslib::value_box() breaks Quarto dashboards
2 participants