Skip to content

Commit

Permalink
Keep dark theme class while in-page updates happen. (#7934)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Aug 15, 2024
1 parent f2277b9 commit b08cc54
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/web_app/lib/src/page_updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ Document _update(
required bool pushState,
required String? url,
}) {
// The dark theme preference is encoded in the `<body>` 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;
Expand Down

0 comments on commit b08cc54

Please sign in to comment.