Skip to content

Commit aff3fec

Browse files
no flashing when reloading in light or dark mode
fixes #1325 introduces a new script before the body which runs immediately, enabling or disabling dark mode TODO: needs to degrade properly when JS is disabled
1 parent 2ae62ed commit aff3fec

File tree

6 files changed

+883
-867
lines changed

6 files changed

+883
-867
lines changed

news/changelog-1.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ All changes included in 1.7:
4444
## `html` format
4545

4646
- ([#11860](https://github.com/quarto-dev/quarto-cli/issues/11860)): ES6 modules that import other local JS modules in documents with `embed-resources: true` are now correctly embedded.
47+
- ([#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.)
4748

4849
## `pdf` format
4950

src/command/render/pandoc-html.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,6 @@ function attribForThemeStyle(
570570
mode === "dark" ? " quarto-color-alternate" : ""
571571
}`,
572572
};
573-
if (disabled) {
574-
attr.rel = "prefetch";
575-
}
576573
return attr;
577574
};
578575

src/format/html/format-html.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
kFigResponsive,
2525
kFilterParams,
2626
kHeaderIncludes,
27+
kIncludeBeforeBody,
2728
kIncludeAfterBody,
2829
kIncludeInHeader,
2930
kLinkExternalFilter,
@@ -501,28 +502,33 @@ export async function htmlFormatExtras(
501502
renderEjs(
502503
formatResourcePath("html", join("hypothesis", "hypothesis.ejs")),
503504
{ hypothesis: options.hypothesis },
504-
),
505+
)
505506
);
506507
includeInHeader.push(hypothesisHeader);
507508
}
508509

509-
// after body
510+
// before and after body
511+
const includeBeforeBody: string[] = [];
510512
const includeAfterBody: string[] = [];
511513

512514
// add main orchestion script if we have any options enabled
513515
const quartoHtmlRequired = Object.keys(options).some((option) =>
514516
!!options[option]
515517
);
516518
if (quartoHtmlRequired) {
517-
// html orchestration script
518-
const quartoHtmlScript = temp.createFile();
519-
const renderedHtml = renderEjs(
520-
formatResourcePath("html", join("templates", "quarto-html.ejs")),
521-
options,
522-
);
523-
if (renderedHtml.trim() !== "") {
524-
Deno.writeTextFileSync(quartoHtmlScript, renderedHtml);
525-
includeAfterBody.push(quartoHtmlScript);
519+
for(const {dest, ejsfile} of [
520+
{dest: includeBeforeBody, ejsfile: "quarto-html-before-body.ejs"},
521+
{dest: includeAfterBody, ejsfile: "quarto-html-after-body.ejs"}
522+
]) {
523+
const quartoHtmlScript = temp.createFile();
524+
const renderedHtml = renderEjs(
525+
formatResourcePath("html", join("templates", ejsfile)),
526+
options,
527+
);
528+
if (renderedHtml.trim() !== "") {
529+
Deno.writeTextFileSync(quartoHtmlScript, renderedHtml);
530+
dest.push(quartoHtmlScript);
531+
}
526532
}
527533
}
528534

@@ -636,6 +642,7 @@ export async function htmlFormatExtras(
636642
const metadata: Metadata = {};
637643
return {
638644
[kIncludeInHeader]: includeInHeader,
645+
[kIncludeBeforeBody]: includeBeforeBody,
639646
[kIncludeAfterBody]: includeAfterBody,
640647
metadata,
641648
templateContext,

0 commit comments

Comments
 (0)