Skip to content
Source
Sign inSign up
TanStack/form

fix(react-form-devtools): re-mount Solid component on theme change (closes #2357) #2371

Opendikshit-n(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/2371/headopened

Showing 3 changed files with 188 additions and 9 deletions.

x
0 of 3 viewed, 3 left
59 additions and 5 deletionspackages/react-form-devtools/src/FormDevtools.tsxModified
View file
@@ -1,12 +1,66 @@
-import { createReactPanel } from '@tanstack/devtools-utils/react'
+import { useEffect, useRef } from 'react'
import { FormDevtoolsCore } from '@tanstack/form-devtools'
​
-// type
import type { DevtoolsPanelProps } from '@tanstack/devtools-utils/react'
​
export interface FormDevtoolsReactInit extends DevtoolsPanelProps {}
​
-const [FormDevtoolsPanel, FormDevtoolsPanelNoOp] =
- createReactPanel(FormDevtoolsCore)
+/**
+ * Fixed React panel wrapper for FormDevtoolsCore.
+ *
+ * Root cause of #2357 ("devtools are always light mode even if TanStackDevtools says dark"):
+ * The original createReactPanel hook only calls mount() once on the Solid FormDevtoolsCore
+ * class. When TanStack DevTools outer shell switches theme, it calls
+ * plugin.render(el, newTheme) which creates a new React element — but mount() is never
+ * called again. The Solid component receives props.theme as a plain (non-reactive) value
+ * and never re-renders.
+ *
+ * Fix: track the previous theme in a ref. The effect dependency is [theme] only — it
+ * fires only when the theme value changes, never on unrelated prop changes. The ref
+ * guards against the initial mount where prevThemeRef.current is undefined (matching
+ * an undefined theme on first render). Cleanup unmounts the old Solid instance both
+ * on theme change and on component teardown, releasing the Solid tree and its
+ * resources.
+ */
+export function FormDevtoolsPanel(props: DevtoolsPanelProps) {
+ const devToolRef = useRef<HTMLDivElement>(null)