Skip to content

Commit

Permalink
chore: Don't need to delay binding
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Jan 23, 2025
1 parent b9f3094 commit 4040039
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
7 changes: 3 additions & 4 deletions srcts/src/shiny/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import { renderHtml as singletonsRenderHtml } from "./singletons";
async function renderContentAsync(
el: BindScope,
content: string | { html: string; deps?: HtmlDep[] } | null,
where: WherePosition = "replace",
doBindAll = true
where: WherePosition = "replace"
): Promise<void> {
if (where === "replace") {
shinyUnbindAll(el);
Expand All @@ -63,7 +62,7 @@ async function renderContentAsync(

if (where === "replace") {
shinyInitializeInputs(el);
if (doBindAll) await shinyBindAll(el);
await shinyBindAll(el);
} else {
const $parent = $(el).parent();

Expand All @@ -76,7 +75,7 @@ async function renderContentAsync(
}
}
shinyInitializeInputs(scope);
if (doBindAll) await shinyBindAll(scope);
await shinyBindAll(scope);
}
}

Expand Down
11 changes: 4 additions & 7 deletions srcts/src/shiny/shinyapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,9 @@ class ShinyApp {

// Create a virtual element where we'll temporarily hold the rendered
// nav controls so we can rewrite some attributes and choose where to
// insert the new controls. (We bindAll() at the end.)
// insert the new controls.
const $fragLi = $("<div>");
await renderContentAsync($fragLi, message.liTag, "afterBegin", false);
await renderContentAsync($fragLi, message.liTag, "afterBegin");

const $liTag = $($fragLi).find("> li");
const $aTag = $liTag.find("> a");
Expand Down Expand Up @@ -1159,9 +1159,8 @@ class ShinyApp {
//
// garrick 2025-01-23: Keeping in mind the above, the `shiny-insert-tab`
// method was re-written to avoid adding the nav controls (liTag) and
// the nav panel contents (divTag) twice. With the new approach, we use
// renderContentAsync() to add both sections of content to the DOM only
// once, but we delay binding until all of the elements are in place.
// the nav panel contents (divTag) twice. Now, we use
// renderContentAsync() to add both sections to the DOM only once.

await renderContentAsync($tabContent[0], message.divTag, "beforeEnd");

Expand All @@ -1170,8 +1169,6 @@ class ShinyApp {
$tabContent.find('[id="tab-tsid-id"]').attr("id", fixupDivId);
}

await shinyBindAll($parentTabset);

if (message.select) {
$liTag.find("a").tab("show");
}
Expand Down

0 comments on commit 4040039

Please sign in to comment.