Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-peas-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@viamrobotics/motion-tools": patch
---

Fix tweakpane styling race condition
18 changes: 13 additions & 5 deletions src/lib/components/App.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts">
import type { Struct } from '@viamrobotics/sdk'
import type { Entity } from 'koota'
import type { Snippet } from 'svelte'

import { Canvas } from '@threlte/core'
import { PortalTarget } from '@threlte/extras'
import { useXR } from '@threlte/xr'
import { provideToast, ToastContainer } from '@viamrobotics/prime-core'
import { primeTheme } from '@viamrobotics/tweakpane-config'
import { onMount, type Snippet } from 'svelte'
import { ThemeUtils } from 'svelte-tweakpane-ui'

import type { FragmentInfo } from '$lib/hooks/useFragmentInfo.svelte'
Expand Down Expand Up @@ -88,6 +88,18 @@
details,
}: Props = $props()

/**
* Apply the Viam tweakpane theme to `<html>` here in setup, before any child
* is created. This must not be deferred to `onMount`: a parent's `onMount`
* runs only after all of its children have mounted, and each child `<Pane>`
* builds its underlying Tweakpane instance during its own setup. So by the
* time App's `onMount` fired the panes already existed and could paint with
* Tweakpane's default dark theme before the theme variables reached `<html>`.
* Running in setup guarantees the variables are set before any pane is built.
* `setGlobalDefaultTheme` no-ops when there is no document (prerender).
*/
ThemeUtils.setGlobalDefaultTheme(primeTheme)

provideWorld()
provideSettingsTabs()

Expand Down Expand Up @@ -122,10 +134,6 @@
environment.current.isStandalone = !localConfigProps
})

onMount(() => {
ThemeUtils.setGlobalDefaultTheme(primeTheme)
})

const selected = useQuery(traits.Selected)
</script>

Expand Down
Loading