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/solid-pacer-devtools-panel-reactivity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/solid-pacer-devtools': patch
---

Pass `theme` and `devtoolsOpen` to the devtools panel reactively, so later changes to these props reach the panel.
8 changes: 6 additions & 2 deletions packages/solid-pacer-devtools/src/SolidPacerDevtools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ type PacerDevtoolsPanelComponent = (

function resolvePanelProps(props?: PacerDevtoolsSolidInit): DevtoolsPanelProps {
return {
theme: props?.theme ?? 'dark',
devtoolsOpen: props?.devtoolsOpen ?? false,
get theme() {
return props?.theme ?? 'dark'
},
get devtoolsOpen() {
return props?.devtoolsOpen ?? false
},
}
}

Expand Down
58 changes: 58 additions & 0 deletions packages/solid-pacer-devtools/tests/panel-reactivity.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { createRoot, createSignal } from 'solid-js'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { PacerDevtoolsPanel } from '../src/SolidPacerDevtools'
import type { DevtoolsPanelProps } from '@tanstack/devtools-utils/solid'

const panelProps: Array<DevtoolsPanelProps> = []

vi.mock(import('@tanstack/devtools-utils/solid'), async (importOriginal) => ({
...(await importOriginal()),
createSolidPanel: () => [
(props) => {
panelProps.push(props)
return null
},
() => null,
],
}))

describe('PacerDevtoolsPanel reactivity', () => {
beforeEach(() => {
panelProps.length = 0
})

it('should pass the latest theme and devtoolsOpen to the panel', () => {
const [theme, setTheme] = createSignal<DevtoolsPanelProps['theme']>('light')
const [devtoolsOpen, setDevtoolsOpen] = createSignal(false)

const dispose = createRoot((dispose) => {
;<PacerDevtoolsPanel theme={theme()} devtoolsOpen={devtoolsOpen()} />
return dispose
})

expect(panelProps).toHaveLength(1)
expect(panelProps[0]?.theme).toBe('light')
expect(panelProps[0]?.devtoolsOpen).toBe(false)

setTheme('dark')
setDevtoolsOpen(true)

expect(panelProps).toHaveLength(1)
expect(panelProps[0]?.theme).toBe('dark')
expect(panelProps[0]?.devtoolsOpen).toBe(true)

dispose()
})

it('should fall back to the default theme and devtoolsOpen', () => {
const dispose = createRoot((dispose) => {
;<PacerDevtoolsPanel />
return dispose
})

expect(panelProps[0]?.theme).toBe('dark')
expect(panelProps[0]?.devtoolsOpen).toBe(false)

dispose()
})
})
Loading