Revert #9554 Refactor stylesheets in single <style> tags

These changes break the palette switcher
This commit is contained in:
Jeremy Ruston 2026-01-18 11:40:10 +00:00
parent be84dee26b
commit ae4e99951a
7 changed files with 35 additions and 43 deletions

View file

@ -17,7 +17,7 @@ exports.synchronous = true;
// Default story and history lists
var PAGE_TITLE_TITLE = "$:/core/wiki/title";
var ROOT_STYLESHEET_TITLE = "$:/core/ui/RootStylesheet";
var PAGE_STYLESHEET_TITLE = "$:/core/ui/PageStylesheet";
var PAGE_TEMPLATE_TITLE = "$:/core/ui/RootTemplate";
// Time (in ms) that we defer refreshing changes to draft tiddlers
@ -44,13 +44,22 @@ exports.startup = function() {
publishTitle();
}
});
var styleParser = $tw.wiki.parseTiddler(ROOT_STYLESHEET_TITLE,{parseAsInline: true}),
styleWidgetNode = $tw.wiki.makeWidget(styleParser,{document: document});
styleWidgetNode.render(document.head,null);
// Set up the styles
$tw.styleWidgetNode = $tw.wiki.makeTranscludeWidget(PAGE_STYLESHEET_TITLE,{document: $tw.fakeDocument});
$tw.styleContainer = $tw.fakeDocument.createElement("style");
$tw.styleWidgetNode.render($tw.styleContainer,null);
$tw.styleWidgetNode.assignedStyles = $tw.styleContainer.textContent;
$tw.styleElement = document.createElement("style");
$tw.styleElement.innerHTML = $tw.styleWidgetNode.assignedStyles;
document.head.insertBefore($tw.styleElement,document.head.firstChild);
$tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) {
styleWidgetNode.refresh(changes,document.head,null);
if($tw.styleWidgetNode.refresh(changes,$tw.styleContainer,null)) {
var newStyles = $tw.styleContainer.textContent;
if(newStyles !== $tw.styleWidgetNode.assignedStyles) {
$tw.styleWidgetNode.assignedStyles = newStyles;
$tw.styleElement.innerHTML = $tw.styleWidgetNode.assignedStyles;
}
}
}));
// Display the $:/core/ui/PageTemplate tiddler to kick off the display
$tw.perf.report("mainRender",function() {
@ -59,7 +68,7 @@ exports.startup = function() {
$tw.utils.addClass($tw.pageContainer,"tc-page-container-wrapper");
document.body.insertBefore($tw.pageContainer,document.body.firstChild);
$tw.pageWidgetNode.render($tw.pageContainer,null);
$tw.hooks.invokeHook("th-page-refreshed");
$tw.hooks.invokeHook("th-page-refreshed");
})();
// Remove any splash screen elements
var removeList = document.querySelectorAll(".tc-remove-when-wiki-loaded");

View file

@ -63,16 +63,24 @@ exports.startup = function() {
$tw.eventBus.emit("window:closed",{windowID});
},false);
// Set up the styles
var styleParser = $tw.wiki.parseTiddler("$:/core/ui/RootStylesheet",{parseAsInline: true}),
styleWidgetNode = $tw.wiki.makeWidget(styleParser,{document: srcDocument});
styleWidgetNode.render(srcDocument.head,null);
var styleWidgetNode = $tw.wiki.makeTranscludeWidget("$:/core/ui/PageStylesheet",{
document: $tw.fakeDocument,
variables: variables,
importPageMacros: true}),
styleContainer = $tw.fakeDocument.createElement("style");
styleWidgetNode.render(styleContainer,null);
var styleElement = srcDocument.createElement("style");
styleElement.innerHTML = styleContainer.textContent;
srcDocument.head.insertBefore(styleElement,srcDocument.head.firstChild);
// Render the text of the tiddler
var parser = $tw.wiki.parseTiddler(template),
widgetNode = $tw.wiki.makeWidget(parser,{document: srcDocument, parentWidget: $tw.rootWidget, variables: variables});
widgetNode.render(srcDocument.body,srcDocument.body.firstChild);
// Function to handle refreshes
refreshHandler = function(changes) {
styleWidgetNode.refresh(changes);
if(styleWidgetNode.refresh(changes,styleContainer,null)) {
styleElement.innerHTML = styleContainer.textContent;
}
widgetNode.refresh(changes);
};
$tw.wiki.addEventListener("change",refreshHandler);

View file

@ -22,7 +22,9 @@ extension: .html
<div id="styleArea">
{{$:/boot/boot.css||$:/core/templates/css-tiddler}}
</div>
{{$:/core/ui/RootStylesheet||$:/core/templates/wikified-tiddler}}
<style type="text/css">
{{$:/core/ui/PageStylesheet||$:/core/templates/wikified-tiddler}}
</style>
</head>
<body class="tc-body">
{{$:/StaticBanner||$:/core/templates/html-tiddler}}

View file

@ -23,7 +23,9 @@ type: text/vnd.tiddlywiki-html
<div id="styleArea">
{{$:/boot/boot.css||$:/core/templates/css-tiddler}}
</div>
{{$:/core/ui/RootStylesheet||$:/core/templates/wikified-tiddler}}
<style type="text/css">
{{$:/core/ui/PageStylesheet||$:/core/templates/wikified-tiddler}}
</style>
</head>
<body class="tc-body">
{{$:/StaticBanner||$:/core/templates/html-tiddler}}

View file

@ -25,7 +25,6 @@ title: $:/core/templates/tiddlywiki5.html
`{{{ [enlist<saveTiddlerAndShadowsFilter>tag[$:/core/wiki/rawmarkup]] ||$:/core/templates/plain-text-tiddler}}}
{{{ [enlist<saveTiddlerAndShadowsFilter>tag[$:/tags/RawMarkup]] ||$:/core/templates/plain-text-tiddler}}}
{{{ [enlist<saveTiddlerAndShadowsFilter>tag[$:/tags/RawMarkupWikified]] ||$:/core/templates/raw-static-tiddler}}}`
<!--~~ Style section start ~~-->
</head>
<body class="tc-body">
<!--~~ Raw markup for the top of the body section ~~-->

View file

@ -1,13 +0,0 @@
title: $:/core/ui/RootStylesheet
code-body: yes
\import [subfilter{$:/core/config/GlobalImportFilter}]
\whitespace trim
<$let currentTiddler={{$:/language}} languageTitle={{!!name}}>
<$list filter="[all[shadows+tiddlers]tag[$:/tags/Stylesheet]!is[draft]]">
<style type="text/css">
<$text text={{{ [<currentTiddler>addprefix[/* ]addsuffix[ */]] }}}/>
<$transclude $tiddler=<<currentTiddler>> $output="text/plain" $mode="block"/>
</style>
</$list>
</$let>

View file

@ -1,15 +0,0 @@
title: $:/changenotes/5.4.0/#9554
created: 20251212171804335
modified: 20251212171804335
tags: $:/tags/ChangeNote
change-type: performance
change-category: internal
description: Different Stylesheets are now included as single `<style>` tags in the Header
release: 5.4.0
github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/9554
github-contributors: BurningTreeC Leilei332
type: text/vnd.tiddlywiki
Previously, all stylesheets were combined in a single `<style>` tag in the `<head>`.
Now, a separate `<style>` tag is created in the `<head>` for each stylesheet.