Skip to content

Commit

Permalink
fix(frontend): fix initial theme incorrectly rendered on detail pages;
Browse files Browse the repository at this point in the history
Issue was caused by skeleton UI not handling modeSwitches on SSR.
Cf:
- skeletonlabs/skeleton#2598 (comment)
- skeletonlabs/skeleton#905 (comment)
  • Loading branch information
t03i committed Nov 29, 2024
1 parent 221786b commit dee1ce2
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions frontend/src/routes/detail/[slug]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onDestroy, onMount } from "svelte";
import { modeCurrent } from "@skeletonlabs/skeleton";
import { modeCurrent, setInitialClassState } from "@skeletonlabs/skeleton";
import type { CreateQueryResult } from "@tanstack/svelte-query";
import * as Sentry from "@sentry/svelte";
Expand All @@ -9,7 +9,7 @@
import { createGetProteinById } from "$lib/client/tmvisdb";
import type { ProteinInfo } from "$lib/client/model";
import { AnnotationStyleManager } from "$lib/annotations";
import { StructureViewerState } from '$lib/stores/StructureMarksStore';
import { StructureViewerState } from "$lib/stores/StructureMarksStore";
import config from "$lib/config";
Expand Down Expand Up @@ -50,20 +50,22 @@
const { feature } = detail;
if (feature) {
const residues = feature.locations[0].fragments.map((fragment: { start: number; end: number }) => ({
const residues = feature.locations[0].fragments.map(
(fragment: { start: number; end: number }) => ({
start_residue_number: fragment.start,
end_residue_number: fragment.end,
}));
structureState.setHighlight(residues, true);
}),
);
structureState.setHighlight(residues, true);
}
};
const uniprotAcc = data.slug;
Sentry.addBreadcrumb({
category: 'navigation',
category: "navigation",
message: `Loading protein details for: ${uniprotAcc}`,
level: 'info'
level: "info",
});
const {
Expand All @@ -83,14 +85,21 @@
annotationTracks,
} = createAnnotationStore(uniprotAcc, infoQuery);
onMount(() => {
// Dark mode issue with SSR disabled; See:
// - https://github.com/skeletonlabs/skeleton/issues/905#issuecomment-1445231511
// - https://github.com/skeletonlabs/skeleton/issues/2598#issuecomment-2070622735
setInitialClassState();
annotationStyleManager = new AnnotationStyleManager(
rootContainer,
modeCurrent ? "light" : "dark",
$modeCurrent ? "light" : "dark",
);
structureState = new StructureViewerState(annotationStyleManager, annotationStructureSelection);
structureState = new StructureViewerState(
annotationStyleManager,
annotationStructureSelection,
);
const unsubscribe = modeCurrent.subscribe((mode) => {
annotationStyleManager.setTheme(mode ? "light" : "dark");
Expand Down Expand Up @@ -123,7 +132,7 @@
{:else if $structureUrl}
<div class="relative h-full w-full">
<StructureColorSwitcher
structureState={structureState}
{structureState}
annotationStructureSelection={$annotationStructureSelection}
/>
<StructureViewer
Expand Down

0 comments on commit dee1ce2

Please sign in to comment.