Skip to content

Commit

Permalink
fix(conditionalPanel): Coerce condition result to boolean (#4127)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Zyla <[email protected]>
  • Loading branch information
gadenbuie and kamilzyla authored Sep 27, 2024
1 parent cc9b9d4 commit 9d12b0f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

* Fixed a bug introduced in v1.9.0 where the boundaries of hover/click/brush regions on plots were being incorrectly scaled when browser zoom was used. (#4111)

* Fixed a bug in `conditionalPanel()` that would cause the panel to repeatedly show/hide itself when the provided condition was not boolean. (@kamilzyla, #4127)

# shiny 1.9.0

## New busy indication feature
Expand Down
2 changes: 1 addition & 1 deletion inst/www/shared/shiny.js
Original file line number Diff line number Diff line change
Expand Up @@ -23917,7 +23917,7 @@
}
var nsPrefix = el.attr("data-ns-prefix");
var nsScope = this._narrowScope(scope, nsPrefix);
var show3 = condFunc(nsScope);
var show3 = Boolean(condFunc(nsScope));
var showing = el.css("display") !== "none";
if (show3 !== showing) {
if (show3) {
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.

2 changes: 1 addition & 1 deletion srcts/src/shiny/shinyapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class ShinyApp {

const nsPrefix = el.attr("data-ns-prefix") as string;
const nsScope = this._narrowScope(scope, nsPrefix);
const show = condFunc(nsScope);
const show = Boolean(condFunc(nsScope));
const showing = el.css("display") !== "none";

if (show !== showing) {
Expand Down
6 changes: 3 additions & 3 deletions srcts/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function pixelRatio(): number {
//
// When the function is executed, it will evaluate that expression using
// "with" on the argument value, and return the result.
function scopeExprToFunc(expr: string): (scope: unknown) => boolean {
function scopeExprToFunc(expr: string): (scope: unknown) => unknown {
/*jshint evil: true */
const exprEscaped = expr
.replace(/[\\"']/g, "\\$&")
Expand All @@ -159,7 +159,7 @@ function scopeExprToFunc(expr: string): (scope: unknown) => boolean {
// \b has a special meaning; need [\b] to match backspace char.
.replace(/[\b]/g, "\\b");

let func: () => boolean;
let func: () => unknown;

try {
// @ts-expect-error; Do not know how to type this _dangerous_ situation
Expand All @@ -178,7 +178,7 @@ function scopeExprToFunc(expr: string): (scope: unknown) => boolean {
throw e;
}

return function (scope: unknown): boolean {
return function (scope: unknown): unknown {
return func.call(scope);
};
}
Expand Down
2 changes: 1 addition & 1 deletion srcts/types/src/utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare function parseDate(dateString: string): Date;
declare function formatDateUTC(x: Date): string;
declare function makeResizeFilter(el: HTMLElement, func: (width: HTMLElement["offsetWidth"], height: HTMLElement["offsetHeight"]) => void): () => void;
declare function pixelRatio(): number;
declare function scopeExprToFunc(expr: string): (scope: unknown) => boolean;
declare function scopeExprToFunc(expr: string): (scope: unknown) => unknown;
declare function asArray<T>(value: T | T[] | null | undefined): T[];
declare function mergeSort<Item>(list: Item[], sortfunc: (a: Item, b: Item) => boolean | number): Item[];
declare function $escape(val: undefined): undefined;
Expand Down

0 comments on commit 9d12b0f

Please sign in to comment.