Skip to content

Commit

Permalink
Avoid SSR fetch (#1180)
Browse files Browse the repository at this point in the history
* Fetch resource types on mount to avoid calling fetch during SSR
* Hide TimelineTimeDisplay if plan does not yet exist to avoid flash of undefined text
* Manually reset activity subscription stores on general reset
  • Loading branch information
AaronPlave authored Mar 26, 2024
1 parent 3827585 commit 57b82cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/components/timeline/Timeline.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,13 @@

<div bind:this={timelineDiv} bind:clientWidth class="timeline" id={`timeline-${timeline?.id}`}>
<div bind:this={timelineHistogramDiv} class="timeline-time-row">
<TimelineTimeDisplay
planEndTimeDoy={plan?.end_time_doy}
planStartTimeDoy={plan?.start_time_doy}
width={timeline?.marginLeft}
/>
{#if plan}
<TimelineTimeDisplay
planEndTimeDoy={plan?.end_time_doy}
planStartTimeDoy={plan?.start_time_doy}
width={timeline?.marginLeft}
/>
{/if}
<div class="timeline-histogram-container">
<TimelineHistogram
activityDirectives={timeline && activityDirectivesByView?.byTimelineId[timeline.id]
Expand Down
15 changes: 9 additions & 6 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<svelte:options immutable={true} />

<script lang="ts">
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/stores';
Expand Down Expand Up @@ -267,12 +268,6 @@
activityTypes.updateValue(() => data.initialActivityTypes);
planTags.updateValue(() => data.initialPlanTags);
// Asynchronously fetch resource types
effects.getResourceTypes($plan.model_id, data.user).then(initialResourceTypes => {
$resourceTypes = initialResourceTypes;
$resourceTypesLoading = false;
});
}
$: if (data.initialPlanSnapshotId !== null) {
$planSnapshotId = data.initialPlanSnapshotId;
Expand Down Expand Up @@ -391,6 +386,14 @@
response => response.errors?.length,
).length;
$: if ($plan && browser) {
// Asynchronously fetch resource types
effects.getResourceTypes($plan.model_id, data.user).then(initialResourceTypes => {
$resourceTypes = initialResourceTypes;
$resourceTypesLoading = false;
});
}
onDestroy(() => {
resetActivityStores();
resetConstraintStores();
Expand Down
4 changes: 4 additions & 0 deletions src/stores/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,8 @@ export function resetActivityStores() {
activityMetadataDefinitions.updateValue(() => []);
activityDirectivesMap.set({});
selectedActivityDirectiveId.set(null);
activityDirectives.updateValue(() => []);
anchorValidationStatuses.updateValue(() => []);
activityMetadataDefinitions.updateValue(() => []);
activityDirectiveValidationStatuses.updateValue(() => []);
}

0 comments on commit 57b82cd

Please sign in to comment.