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

fix(conditionalPanel): Coerce condition result to boolean #4127

Merged
merged 8 commits into from
Sep 27, 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
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);
schloerke marked this conversation as resolved.
Show resolved Hide resolved
};
}
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
Loading