Skip to content

Commit f261541

Browse files
authored
Merge pull request #12520 from quarto-dev/bugfix/11338
dashboard - properly cleanup unused library
2 parents 05138c1 + 36fd1f2 commit f261541

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

news/changelog-1.7.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ All changes included in 1.7:
6464

6565
## Formats
6666

67-
## `html`
67+
### `dashboard`
68+
69+
- ([#11338](https://github.com/quarto-dev/quarto-cli/issues/11338)): Remove unused datatables imports when appropriate.
70+
71+
### `html`
6872

6973
- ([#1325](https://github.com/quarto-dev/quarto-cli/issues/1325)): Dark Mode pages should not flash light on reload. (Nor should Light Mode pages flash dark.)
7074
- ([#1470](https://github.com/quarto-dev/quarto-cli/issues/1470)): `respect-user-color-scheme` enables checking the media query `prefers-color-scheme` for user dark mode preference. Author preference still influences stylesheet order and NoJS experience. Defaults to `false`, leaving to author preference.
@@ -76,7 +80,7 @@ All changes included in 1.7:
7680
- ([#12319](https://github.com/quarto-dev/quarto-cli/pull/12319)): Provide switchable light and dark brands for a page with `brand.light` and `brand.dark`.
7781
- ([#12356](https://github.com/quarto-dev/quarto-cli/issues/12356)): Remove duplicate id in HTML document when using `#lst-` prefix label for using Quarto crossref.
7882

79-
## `pdf`
83+
### `pdf`
8084

8185
- ([#11695](https://github.com/quarto-dev/quarto-cli/issues/11695)): Translate ANSI color codes more carefully inside `highlighting` environments.
8286
- ([#11835](https://github.com/quarto-dev/quarto-cli/issues/11835)): Take markdown structure into account when detecting minimum heading level.
@@ -93,16 +97,16 @@ All changes included in 1.7:
9397
- New Quarto partials: `babel-lang.tex`, `biblio-config.tex`. Quarto's partials uses `.tex` extension.
9498
- BREAKING CHANGE for templates authors: `common.latex` does now uses `pandoc.tex` partial from Quarto, which include now part of the content that was in main `template.tex`. If you modify `pandoc.tex` as part of a custom format, it should be updated to new content.
9599

96-
## `jats`
100+
### `jats`
97101

98102
- Update to Pandoc's template following Pandoc 3.6.3 support:
99103
- `article.jats_publishing` partials now support `author.roles`
100104

101-
## `revealjs`
105+
### `revealjs`
102106

103107
- ([#12307](https://github.com/quarto-dev/quarto-cli/issues/12307)): Tabsets using `tabby.js` in Revealjs now correctly render reactive content when `server: shiny` is used.
104108

105-
## `typst` format
109+
### `typst` format
106110

107111
- ([#11578](https://github.com/quarto-dev/quarto-cli/issues/11578)): Typst column layout widths use fractional `fr` units instead of percent `%` units for unitless and default widths in order to fill the enclosing block and not spill outside it.
108112
- ([#11676](https://github.com/quarto-dev/quarto-cli/pull/11676)): Convert unitless image widths from pixels to inches for column layouts.

src/format/dashboard/format-dashboard-tables.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export function processDatatables(
3535
const scriptNodes = doc.querySelectorAll(
3636
".cell-output script[type='module']",
3737
);
38+
39+
let keepDeps = false;
40+
3841
for (const scriptNode of scriptNodes) {
3942
const scriptEl = scriptNode as Element;
4043
const code = scriptEl.innerText;
@@ -57,6 +60,7 @@ export function processDatatables(
5760
}
5861

5962
if (hasConnectedDt) {
63+
keepDeps = true;
6064
// Replace the table initialization
6165
const codeText = codeFiltered.join("\n");
6266
// for iTables < 1.7, do fixups
@@ -82,21 +86,23 @@ export function processDatatables(
8286
linkCssEl.remove();
8387
}
8488
}
85-
86-
// We found tables, clear the DT sentinel attr
87-
const dtNodes = doc.querySelectorAll(`[${kDTTableSentinel}="true"]`);
88-
dtNodes.forEach((node) => {
89-
(node as Element).removeAttribute(kDTTableSentinel);
90-
});
91-
} else {
92-
// We didn't find any DT, remove the dependencies that we injected at the root level
93-
const dtNodes = doc.querySelectorAll(`[${kDTTableSentinel}="true"]`);
94-
dtNodes.forEach((node) => {
95-
(node as Element).remove();
96-
});
9789
}
9890
}
9991

92+
if (keepDeps) {
93+
// We found tables, clear the DT sentinel attr
94+
const dtNodes = doc.querySelectorAll(`[${kDTTableSentinel}="true"]`);
95+
dtNodes.forEach((node) => {
96+
(node as Element).removeAttribute(kDTTableSentinel);
97+
});
98+
} else {
99+
// We didn't find any DT, remove the dependencies that we injected at the root level
100+
const dtNodes = doc.querySelectorAll(`[${kDTTableSentinel}="true"]`);
101+
dtNodes.forEach((node) => {
102+
(node as Element).remove();
103+
});
104+
}
105+
100106
return {
101107
resources,
102108
supporting,

src/format/dashboard/format-dashboard.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { ProjectContext } from "../../project/types.ts";
3636
import { registerWriterFormatHandler } from "../format-handlers.ts";
3737
import { kPageLayout, kPageLayoutCustom } from "../html/format-html-shared.ts";
3838
import { htmlFormat } from "../html/format-html.ts";
39+
import { kDTTableSentinel } from "./format-dashboard-shared.ts";
3940

4041
import { join } from "../../deno_ral/path.ts";
4142
import {
@@ -199,7 +200,7 @@ export function dashboardFormat() {
199200
join("js", "dt", "datatables.min.js"),
200201
),
201202
attribs: {
202-
kDTTableSentinel: "true",
203+
[kDTTableSentinel]: "true",
203204
},
204205
});
205206
stylesheets.push({
@@ -209,7 +210,7 @@ export function dashboardFormat() {
209210
join("js", "dt", "datatables.min.css"),
210211
),
211212
attribs: {
212-
kDTTableSentinel: "true",
213+
[kDTTableSentinel]: "true",
213214
},
214215
});
215216
scripts.push({
@@ -219,7 +220,7 @@ export function dashboardFormat() {
219220
join("js", "dt", "pdfmake.min.js"),
220221
),
221222
attribs: {
222-
kDTTableSentinel: "true",
223+
[kDTTableSentinel]: "true",
223224
},
224225
});
225226
scripts.push({
@@ -229,7 +230,7 @@ export function dashboardFormat() {
229230
join("js", "dt", "vfs_fonts.js"),
230231
),
231232
attribs: {
232-
kDTTableSentinel: "true",
233+
[kDTTableSentinel]: "true",
233234
},
234235
});
235236

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
format: dashboard
3+
_quarto:
4+
tests:
5+
dashboard:
6+
ensureFileRegexMatches:
7+
- []
8+
- ["kdttablesentinel"]
9+
---

0 commit comments

Comments
 (0)