Skip to content

Commit 2a6274c

Browse files
committed
fix(containers): fix showComposeTab reactivity — use IIFE inside $derived not a stored function
$derived((): boolean => {...}) stores a function as the derived value; Svelte 5 doesn't track reactive reads (project, composeServiceName) when the stored function is called later from inside tabItems. Use an IIFE inside $derived instead so the boolean is computed directly and reactivity is properly tracked.
1 parent 02c7080 commit 2a6274c

File tree

1 file changed

+17
-11
lines changed
  • frontend/src/routes/(app)/containers/[containerId]

1 file changed

+17
-11
lines changed

frontend/src/routes/(app)/containers/[containerId]/+page.svelte

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,21 @@
231231
// Only show the Compose tab if the service is directly defined in the project's compose file.
232232
// When a project uses `include:` directives, the root compose is just a wrapper — not useful
233233
// to edit from a container view. In that case we hide the tab entirely.
234-
const showComposeTab = $derived((): boolean => {
235-
if (!project?.composeContent || !composeServiceName) return false;
236-
try {
237-
const parsed = parseYaml(project.composeContent) as Record<string, unknown> | null;
238-
return !!parsed?.services && !!(parsed.services as Record<string, unknown>)[composeServiceName];
239-
} catch {
240-
return false;
241-
}
242-
});
234+
const showComposeTab = $derived(
235+
!!project?.composeContent &&
236+
!!composeServiceName &&
237+
(() => {
238+
try {
239+
const parsed = parseYaml(project!.composeContent!) as Record<string, unknown> | null;
240+
return (
241+
!!parsed?.services &&
242+
!!(parsed.services as Record<string, unknown>)[composeServiceName]
243+
);
244+
} catch {
245+
return false;
246+
}
247+
})()
248+
);
243249
244250
const tabItems = $derived<TabItem[]>([
245251
{ value: 'overview', label: m.common_overview(), icon: ContainersIcon },
@@ -249,7 +255,7 @@
249255
...(showConfiguration ? [{ value: 'config', label: m.common_configuration(), icon: SettingsIcon }] : []),
250256
...(showNetworkTab ? [{ value: 'network', label: m.containers_nav_networks(), icon: NetworksIcon }] : []),
251257
...(hasMounts ? [{ value: 'storage', label: m.containers_nav_storage(), icon: VolumesIcon }] : []),
252-
...(showComposeTab() ? [{ value: 'compose', label: 'Compose', icon: CodeIcon }] : [])
258+
...(showComposeTab ? [{ value: 'compose', label: 'Compose', icon: CodeIcon }] : [])
253259
]);
254260
255261
$effect(() => {
@@ -404,7 +410,7 @@
404410
</Tabs.Content>
405411
{/if}
406412

407-
{#if project && showComposeTab()}
413+
{#if project && showComposeTab}
408414
<Tabs.Content value="compose" class="h-full min-h-0">
409415
<ContainerComposePanel {project} serviceName={composeServiceName} />
410416
</Tabs.Content>

0 commit comments

Comments
 (0)