Skip to content

Commit

Permalink
Warn instead of error when duplicate binding IDs are found in non-dev…
Browse files Browse the repository at this point in the history
…mode (#4019)

* Close #4016. Warn instead of error when duplicate binding IDs are found in non-devmode

* Get rid of unreachable ShinyClientError()

* `yarn build` (GitHub Actions)

* Update srcts/src/shiny/bind.ts

Co-authored-by: Garrick Aden-Buie <[email protected]>

* `yarn build` (GitHub Actions)

* Move logic to where error gets thrown not constructed

* `yarn build` (GitHub Actions)

* Update NEWS

---------

Co-authored-by: cpsievert <[email protected]>
Co-authored-by: Garrick Aden-Buie <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2024
1 parent 47526a7 commit edd1db7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
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

0 comments on commit edd1db7

Please sign in to comment.