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

Warn instead of error when duplicate binding IDs are found in non-devmode #4019

Merged
merged 8 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# shiny (development version)

* In v1.8.1, shiny.js starting throwing an error when input/output bindings have duplicate IDs. This error is now only thrown when `shiny::devmode(TRUE)` is enabled, so the issue is still made discoverable through the JS error console, but avoids unnecessarily breaking apps that happen to work with duplicate IDs. (#4019)

# shiny 1.8.1

## New features and improvements
Expand Down
18 changes: 9 additions & 9 deletions inst/www/shared/shiny.js
Original file line number Diff line number Diff line change
Expand Up @@ -18604,12 +18604,6 @@
};
}
function addBinding(id, bindingType) {
if (id === "") {
throw new ShinyClientError({
headline: "Empty ".concat(bindingType, " ID found"),
message: "Binding IDs must not be empty."
});
}
var existingBinding = bindings.get(id);
if (existingBinding) {
existingBinding.push(bindingType);
Expand Down Expand Up @@ -18848,13 +18842,19 @@
currentInputs = bindInputs(shinyCtx, scope);
bindingValidity = bindingsRegistry.checkValidity();
if (!(bindingValidity.status === "error")) {
_context2.next = 6;
_context2.next = 10;
break;
}
if (!Shiny.inDevMode()) {
_context2.next = 9;
break;
}
throw bindingValidity.error;
case 6:
case 9:
console.warn("[shiny] " + bindingValidity.error.message);
case 10:
return _context2.abrupt("return", currentInputs);
case 7:
case 11:
case "end":
return _context2.stop();
}
Expand Down
4 changes: 2 additions & 2 deletions inst/www/shared/shiny.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions inst/www/shared/shiny.min.js.map

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions srcts/src/shiny/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ const bindingsRegistry = (() => {
* @param bindingType Binding type, either "input" or "output"
*/
function addBinding(id: string, bindingType: BindingTypes): void {
if (id === "") {
throw new ShinyClientError({
headline: `Empty ${bindingType} ID found`,
message: "Binding IDs must not be empty.",
});
}

const existingBinding = bindings.get(id);

if (existingBinding) {
Expand Down Expand Up @@ -427,7 +420,12 @@ async function _bindAll(
// re-run, and then see the next collision, etc.
const bindingValidity = bindingsRegistry.checkValidity();
if (bindingValidity.status === "error") {
throw bindingValidity.error;
// Only throw if we're in dev mode. Otherwise, just log a warning.
if (Shiny.inDevMode()) {
throw bindingValidity.error;
} else {
console.warn("[shiny] " + bindingValidity.error.message);
}
}

return currentInputs;
Expand Down