Skip to content

Commit 87dbb89

Browse files
authored
Merge pull request #13158 from gitbutlerapp/fix-warnings
Suppress Svelte 5 state_referenced_locally warnings with untrack()
2 parents 4c0a131 + a174264 commit 87dbb89

51 files changed

Lines changed: 159 additions & 99 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/desktop/src/components/branch/BranchIntegrationModal.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
} from "$lib/upstream/integrationStepUtils";
2525
import { inject } from "@gitbutler/core/context";
2626
import { Modal, ModalFooter, Button, ScrollableContainer, SimpleCommitRow } from "@gitbutler/ui";
27+
import { untrack } from "svelte";
2728
import { flip } from "svelte/animate";
2829
import type { InteractiveIntegrationStep } from "$lib/stacks/stack";
2930
@@ -44,9 +45,9 @@
4445
const stackService = inject(STACK_SERVICE);
4546
const [integrate, integrating] = stackService.integrateBranchWithSteps;
4647
const initialIntegrationSteps = stackService.initialIntegrationSteps(
47-
projectId,
48-
stackId,
49-
branchName,
48+
untrack(() => projectId),
49+
untrack(() => stackId),
50+
untrack(() => branchName),
5051
);
5152
5253
let editableSteps = $derived(initialIntegrationSteps.response ?? []);

apps/desktop/src/components/codegen/CodegenPromptConfigModal.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { Codeblock } from "@gitbutler/ui";
33
import { Modal, SegmentControl, Button } from "@gitbutler/ui";
4+
import { untrack } from "svelte";
45
import type { PromptDir } from "$lib/codegen/types";
56
67
type Props = {
@@ -16,7 +17,7 @@
1617
1718
const { promptDirs, openPromptConfigDir }: Props = $props();
1819
19-
let selectedSegment = $state<string>(promptDirs[0]?.label || "");
20+
let selectedSegment = $state<string>(untrack(() => promptDirs[0]?.label || ""));
2021
</script>
2122

2223
{#snippet pathContent({ path, caption }: { path: string; caption: string })}

apps/desktop/src/components/codegen/CodegenServiceMessageThinking.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import CodegenServiceMessage from "$components/codegen/CodegenServiceMessage.svelte";
3+
import { untrack } from "svelte";
34
45
type Props = {
56
startAt: Date;
@@ -71,7 +72,9 @@
7172
}
7273
7374
let currentWord = $state(getWord());
74-
let currentDuration = $state(milisToEnglish(Date.now() - startAt.getTime() - msSpentWaiting));
75+
let currentDuration = $state(
76+
untrack(() => milisToEnglish(Date.now() - startAt.getTime() - msSpentWaiting)),
77+
);
7578
7679
$effect(() => {
7780
const updateWordInterval = setInterval(() => {

apps/desktop/src/components/codegen/CodegenSessionRow.svelte

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import { inject } from "@gitbutler/core/context";
2424
import { Badge, Icon, type IconName } from "@gitbutler/ui";
2525
import { focusable } from "@gitbutler/ui/focus/focusable";
26+
import { untrack } from "svelte";
2627
import { slide } from "svelte/transition";
2728
import type { ClaudeStatus, PromptAttachment } from "$lib/codegen/types";
2829
@@ -46,12 +47,13 @@
4647
draft = false,
4748
}: Props = $props();
4849
49-
const uiState = draft ? undefined : inject(UI_STATE);
50-
const laneState = draft || !stackId ? undefined : uiState?.lane(stackId);
50+
const uiState = untrack(() => draft) ? undefined : inject(UI_STATE);
51+
const laneState = untrack(() => (draft || !stackId ? undefined : uiState?.lane(stackId)));
5152
52-
const claudeService = draft ? undefined : inject(CLAUDE_CODE_SERVICE);
53-
const messages =
54-
draft || !projectId || !stackId ? undefined : claudeService?.messages({ projectId, stackId });
53+
const claudeService = untrack(() => draft) ? undefined : inject(CLAUDE_CODE_SERVICE);
54+
const messages = untrack(() =>
55+
draft || !projectId || !stackId ? undefined : claudeService?.messages({ projectId, stackId }),
56+
);
5557
const permissionRequests = $derived(
5658
draft || !projectId ? undefined : claudeService?.permissionRequests({ projectId }),
5759
);
@@ -69,7 +71,7 @@
6971
return "ai";
7072
}
7173
72-
const attachmentService = draft ? undefined : inject(ATTACHMENT_SERVICE);
74+
const attachmentService = untrack(() => draft) ? undefined : inject(ATTACHMENT_SERVICE);
7375
7476
function addAttachment(items: PromptAttachment[]) {
7577
if (!branchName || !attachmentService) return;

apps/desktop/src/components/codegen/CodegenToolCall.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { formatToolCall, getToolIcon, getToolLabel } from "$lib/codegen/codegenTools";
44
import { toolCallLoading, type ToolCall } from "$lib/codegen/messages";
55
import { Codeblock } from "@gitbutler/ui";
6+
import { untrack } from "svelte";
67
78
type Props = {
89
projectId: string;
@@ -26,10 +27,11 @@
2627
}: Props = $props();
2728
2829
// Initialize expanded state from map, default to false (collapsed)
29-
const initialExpanded =
30+
const initialExpanded = untrack(() =>
3031
toolCallKey && toolCallExpandedState
3132
? (toolCallExpandedState.individual.get(toolCallKey) ?? false)
32-
: false;
33+
: false,
34+
);
3335
3436
function handleToggle(newExpanded: boolean) {
3537
// Persist to map if available

apps/desktop/src/components/commit/CommitFailedModalContent.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import AppScrollableContainer from "$components/shared/AppScrollableContainer.svelte";
44
import { REJECTTION_REASONS, type RejectionReason } from "$lib/stacks/stackService.svelte";
55
import { Icon, ModalHeader, TestId, Tooltip } from "@gitbutler/ui";
6+
import { untrack } from "svelte";
67
import type { CommitFailedModalState } from "$lib/state/uiState.svelte";
78
89
type Props = {
@@ -63,7 +64,7 @@
6364
return result;
6465
}
6566
66-
const groupedData = groupByReason(data);
67+
const groupedData = groupByReason(untrack(() => data));
6768
6869
let isScrollTopVisible = $state(true);
6970
</script>

apps/desktop/src/components/diff/FloatingDiffModal.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import { Button, FileViewHeader, HunkDiffSkeleton, Icon, VirtualList } from "@gitbutler/ui";
2020
import { FOCUS_MANAGER, type FocusableOptions } from "@gitbutler/ui/focus/focusManager";
2121
import { focusable } from "@gitbutler/ui/focus/focusable";
22-
import { tick } from "svelte";
22+
import { tick, untrack } from "svelte";
2323
2424
interface Props {
2525
projectId: string;
@@ -61,7 +61,7 @@
6161
6262
let listMode: "list" | "tree" = $state("list");
6363
// Seeded from prop once on mount; subsequent user selection is independent.
64-
let selectedIndex = $state(initialIndex);
64+
let selectedIndex = $state(untrack(() => initialIndex));
6565
// Prevents VirtualList scroll events from overwriting a user-clicked selection.
6666
const scrollLock = new ScrollSelectionLock(getInitialLockedIndex());
6767
let headerElRef = $state<HTMLDivElement | undefined>(undefined);

apps/desktop/src/components/diff/MultiDiffView.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import { SETTINGS } from "$lib/settings/userSettings";
2424
import { inject } from "@gitbutler/core/context";
2525
import { Button, FileViewHeader, HunkDiffSkeleton, VirtualList } from "@gitbutler/ui";
26+
import { untrack } from "svelte";
2627
2728
type Props = {
2829
projectId: string;
@@ -69,7 +70,7 @@
6970
}
7071
7172
let virtualList = $state<VirtualList<TreeChange>>();
72-
let highlightedIndex = $state<number | undefined>(startIndex);
73+
let highlightedIndex = $state<number | undefined>(untrack(() => startIndex));
7374
// Prevents VirtualList scroll events from overwriting a user-clicked selection.
7475
const scrollLock = new ScrollSelectionLock(getInitialLockedIndex());
7576
let floatingDiffOpen = $state(false);

apps/desktop/src/components/editor/MessageEditor.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
type DropFileResult,
4040
} from "@gitbutler/ui/richText/plugins/FileUpload.svelte";
4141
42-
import { tick } from "svelte";
42+
import { tick, untrack } from "svelte";
4343
4444
const ACCEPTED_FILE_TYPES = ["image/*", "application/*", "text/*", "audio/*", "video/*"];
4545
@@ -92,9 +92,11 @@
9292
9393
const uploadsService = inject(UPLOADS_SERVICE);
9494
const userSettings = inject(SETTINGS);
95-
const commitGenerationExtraConcise = projectCommitGenerationExtraConcise(projectId);
96-
const commitGenerationUseEmojis = projectCommitGenerationUseEmojis(projectId);
97-
const commitGenerationHaiku = projectCommitGenerationHaiku(projectId);
95+
const commitGenerationExtraConcise = projectCommitGenerationExtraConcise(
96+
untrack(() => projectId),
97+
);
98+
const commitGenerationUseEmojis = projectCommitGenerationUseEmojis(untrack(() => projectId));
99+
const commitGenerationHaiku = projectCommitGenerationHaiku(untrack(() => projectId));
98100
99101
const useFloatingBox = uiState.global.useFloatingBox;
100102

apps/desktop/src/components/files/WorktreeChanges.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import { Badge, TestId } from "@gitbutler/ui";
2525
import { focusable } from "@gitbutler/ui/focus/focusable";
2626
import { isDefined } from "@gitbutler/ui/utils/typeguards";
27-
import { type Snippet } from "svelte";
27+
import { untrack, type Snippet } from "svelte";
2828
import type { DropzoneHandler } from "$lib/dragging/handler";
2929
import type { TreeChange } from "$lib/hunks/change";
3030
import type { FileListKeyHandler } from "$lib/selection/fileListController.svelte";
@@ -58,7 +58,7 @@
5858
}: Props = $props();
5959
6060
// Create a unique persist ID based on stackId and mode (both are static props)
61-
const persistId = stackId ? `worktree-${mode}-${stackId}` : `worktree-${mode}`;
61+
const persistId = untrack(() => (stackId ? `worktree-${mode}-${stackId}` : `worktree-${mode}`));
6262
6363
const diffService = inject(DIFF_SERVICE);
6464
const uncommittedService = inject(UNCOMMITTED_SERVICE);

0 commit comments

Comments
 (0)