33 PLUGIN_CONTAINER_ID ,
44 PLUGIN_TITLE_CONTAINER_ID ,
55 TanStackDevtoolsCore ,
6+ generatePluginId ,
67} from '@tanstack/devtools'
78import { createPortal } from 'react-dom'
89import type { JSX , ReactElement } from 'react'
@@ -109,49 +110,67 @@ export const TanStackDevtools = ({
109110 eventBusConfig,
110111} : TanStackDevtoolsReactInit ) : ReactElement | null => {
111112 const devToolRef = useRef < HTMLDivElement > ( null )
112- const [ pluginContainer , setPluginContainer ] = useState < HTMLElement | null > (
113- null ,
113+ const [ pluginContainers , setPluginContainers ] = useState < Array < HTMLElement > > (
114+ [ ] ,
114115 )
115- const [ titleContainer , setTitleContainer ] = useState < HTMLElement | null > ( null )
116- const [ PluginComponent , setPluginComponent ] = useState < JSX . Element | null > (
117- null ,
116+ const [ titleContainers , setTitleContainers ] = useState < Array < HTMLElement > > ( [ ] )
117+ const [ PluginComponents , setPluginComponents ] = useState < Array < JSX . Element > > (
118+ [ ] ,
118119 )
119- const [ TitleComponent , setTitleComponent ] = useState < JSX . Element | null > ( null )
120+ const [ TitleComponents , setTitleComponents ] = useState < Array < JSX . Element > > ( [ ] )
121+
120122 const [ devtools ] = useState (
121123 ( ) =>
122124 new TanStackDevtoolsCore ( {
123125 config,
124126 eventBusConfig,
125- plugins : plugins ?. map ( ( plugin ) => {
127+ plugins : plugins ?. map ( ( plugin , index ) => {
126128 return {
127129 ...plugin ,
128130 name :
129131 typeof plugin . name === 'string'
130132 ? plugin . name
131133 : // The check above confirms that `plugin.name` is of Render type
132134 ( e , theme ) => {
133- setTitleContainer (
134- e . ownerDocument . getElementById (
135- PLUGIN_TITLE_CONTAINER_ID ,
136- ) || null ,
135+ const target = e . ownerDocument . getElementById (
136+ // @ts -ignore just testing
137+ `${ PLUGIN_TITLE_CONTAINER_ID } -${ generatePluginId ( plugin , index ) } ` ,
137138 )
139+ if ( target ) {
140+ setTitleContainers ( ( prev ) => [ ...prev , target ] )
141+ }
138142 convertRender (
139143 plugin . name as PluginRender ,
140- setTitleComponent ,
144+ ( newVal ) =>
145+ // @ts -ignore just testing
146+ setTitleComponents ( ( prev ) => [ ...prev , newVal ] ) ,
141147 e ,
142148 theme ,
143149 )
144150 } ,
145151 render : ( e , theme ) => {
146- setPluginContainer (
147- e . ownerDocument . getElementById ( PLUGIN_CONTAINER_ID ) || null ,
152+ const target = e . ownerDocument . getElementById (
153+ // @ts -ignore just testing
154+ `${ PLUGIN_CONTAINER_ID } -${ generatePluginId ( plugin , index ) } ` ,
155+ )
156+ if ( target ) {
157+ setPluginContainers ( ( prev ) => [ ...prev , target ] )
158+ }
159+
160+ convertRender (
161+ plugin . render ,
162+ ( newVal ) =>
163+ // @ts -ignore just testing
164+ setPluginComponents ( ( prev ) => [ ...prev , newVal ] ) ,
165+ e ,
166+ theme ,
148167 )
149- convertRender ( plugin . render , setPluginComponent , e , theme )
150168 } ,
151169 }
152170 } ) ,
153171 } ) ,
154172 )
173+
155174 useEffect ( ( ) => {
156175 if ( devToolRef . current ) {
157176 devtools . mount ( devToolRef . current )
@@ -163,11 +182,17 @@ export const TanStackDevtools = ({
163182 return (
164183 < >
165184 < div style = { { position : 'absolute' } } ref = { devToolRef } />
166- { pluginContainer && PluginComponent
167- ? createPortal ( < > { PluginComponent } </ > , pluginContainer )
185+
186+ { pluginContainers . length > 0 && PluginComponents . length > 0
187+ ? pluginContainers . map ( ( pluginContainer , index ) =>
188+ createPortal ( < > { PluginComponents [ index ] } </ > , pluginContainer ) ,
189+ )
168190 : null }
169- { titleContainer && TitleComponent
170- ? createPortal ( < > { TitleComponent } </ > , titleContainer )
191+
192+ { titleContainers . length > 0 && TitleComponents . length > 0
193+ ? titleContainers . map ( ( titleContainer , index ) =>
194+ createPortal ( < > { TitleComponents [ index ] } </ > , titleContainer ) ,
195+ )
171196 : null }
172197 </ >
173198 )
0 commit comments