Skip to content

Commit 3d3b05c

Browse files
authored
Correctly render script tags defined as list() objects (#3395)
* Close #3345: correctly render script tags defined as list() objects * implement boolean attrs; use vanilla JS * Update news * avoid toggleAttribute * yarn lint (GitHub Actions) * code review Co-authored-by: cpsievert <[email protected]>
1 parent 543a6b5 commit 3d3b05c

File tree

6 files changed

+145
-17
lines changed

6 files changed

+145
-17
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ shiny 1.6.0.9000
3232

3333
### Bug fixes
3434

35+
* Closed #3345: Shiny now correctly renders `htmltools::htmlDependency()`(s) with a `list()` of `script` attributes when used in a dynamic UI context. This fairly new `htmlDependency()` feature was added in `{htmltools}` v0.5.1. (#3395)
36+
3537
* Closed #3374: `quoToFunction()` now works correctly with nested quosures; and as a result, quasi-quotation with rendering function (e.g., `renderPrint()`, `renderPlot()`, etc) now works as expected with nested quosures. (#3373)
3638

3739
* Exported `register_devmode_option()`. This method was described in the documentation for `devmode()` but was never exported. See `?devmode()` for more details on how to register Shiny Developer options using `register_devmode_option()`. (#3364)

inst/www/shared/shiny.js

Lines changed: 118 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcts/src/main.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4155,8 +4155,24 @@ function main(): void {
41554155
}
41564156

41574157
if (dep.script && !restyle) {
4158-
const scripts = $.map(asArray(dep.script), function (scriptName) {
4159-
return $("<script>").attr("src", href + "/" + encodeURI(scriptName));
4158+
const scripts_attrs = asArray(dep.script);
4159+
const scripts = $.map(scripts_attrs, function (x) {
4160+
let script = document.createElement("script");
4161+
4162+
// htmlDependency()'s script arg can be a character vector or a list()
4163+
if (typeof x === "string") {
4164+
x = { src: x };
4165+
}
4166+
4167+
for (let [attr, val] of Object.entries(x)) {
4168+
if (attr === "src") {
4169+
val = href + "/" + encodeURI(val);
4170+
}
4171+
// If val isn't truthy (e.g., null), consider it a boolean attribute
4172+
script.setAttribute(attr, val ? val : "");
4173+
}
4174+
4175+
return script;
41604176
});
41614177

41624178
$head.append(scripts);

0 commit comments

Comments
 (0)