From b08cc54e68f9c1ac3495cccc942f9a9a85244bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20So=C3=B3s?= Date: Thu, 15 Aug 2024 12:25:52 +0200 Subject: [PATCH] Keep dark theme class while in-page updates happen. (#7934) --- pkg/web_app/lib/src/page_updater.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/web_app/lib/src/page_updater.dart b/pkg/web_app/lib/src/page_updater.dart index 2f043ba6e8..dc0874d013 100644 --- a/pkg/web_app/lib/src/page_updater.dart +++ b/pkg/web_app/lib/src/page_updater.dart @@ -44,8 +44,13 @@ Document _update( required bool pushState, required String? url, }) { + // The dark theme preference is encoded in the `` element's `class` + // attributes. We could re-run the initialization, but storing the current + // values and replacing the provided ones is simpler. + final oldClasses = document.body!.className; final doc = DomParser().parseFromString(html, 'text/html'); document.querySelector('body')!.replaceWith(doc.querySelector('body')!); + document.body!.className = oldClasses; _popStateFn!(); if (pushState) { final title = doc.querySelector('title')?.text;