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'
@@ -103,47 +104,59 @@ export const TanStackDevtools = ({
103104 eventBusConfig,
104105} : TanStackDevtoolsReactInit ) : ReactElement | null => {
105106 const devToolRef = useRef < HTMLDivElement > ( null )
106- const [ pluginContainer , setPluginContainer ] = useState < HTMLElement | null > (
107- null ,
107+ const [ pluginContainers , setPluginContainers ] = useState < Array < HTMLElement > > (
108+ [ ] ,
108109 )
109- const [ titleContainer , setTitleContainer ] = useState < HTMLElement | null > ( null )
110- const [ PluginComponent , setPluginComponent ] = useState < JSX . Element | null > (
111- null ,
110+ const [ titleContainers , setTitleContainers ] = useState < Array < HTMLElement > > ( [ ] )
111+ const [ PluginComponents , setPluginComponents ] = useState < Array < JSX . Element > > (
112+ [ ] ,
112113 )
113- const [ TitleComponent , setTitleComponent ] = useState < JSX . Element | null > ( null )
114+ const [ TitleComponents , setTitleComponents ] = useState < Array < JSX . Element > > ( [ ] )
115+
114116 const [ devtools ] = useState (
115117 ( ) =>
116118 new TanStackDevtoolsCore ( {
117119 config,
118120 eventBusConfig,
119- plugins : plugins ?. map ( ( plugin ) => {
121+ plugins : plugins ?. map ( ( plugin , index ) => {
120122 return {
121123 ...plugin ,
122124 name :
123125 typeof plugin . name === 'string'
124126 ? plugin . name
125127 : // The check above confirms that `plugin.name` is of Render type
126128 ( e ) => {
127- setTitleContainer (
128- e . ownerDocument . getElementById (
129- PLUGIN_TITLE_CONTAINER_ID ,
130- ) || null ,
129+ const target = e . ownerDocument . getElementById (
130+ // @ts -ignore just testing
131+ `${ PLUGIN_TITLE_CONTAINER_ID } -${ generatePluginId ( plugin , index ) } ` ,
131132 )
132- convertRender (
133- plugin . name as PluginRender ,
134- setTitleComponent ,
133+ if ( target ) {
134+ setTitleContainers ( ( prev ) => [ ...prev , target ] )
135+ }
136+ convertRender ( plugin . name as PluginRender , ( newVal ) =>
137+ // @ts -ignore just testing
138+ setTitleComponents ( ( prev ) => [ ...prev , newVal ] ) ,
135139 )
136140 } ,
137141 render : ( e ) => {
138- setPluginContainer (
139- e . ownerDocument . getElementById ( PLUGIN_CONTAINER_ID ) || null ,
142+ const target = e . ownerDocument . getElementById (
143+ // @ts -ignore just testing
144+ `${ PLUGIN_CONTAINER_ID } -${ generatePluginId ( plugin , index ) } ` ,
145+ )
146+ if ( target ) {
147+ setPluginContainers ( ( prev ) => [ ...prev , target ] )
148+ }
149+
150+ convertRender ( plugin . render , ( newVal ) =>
151+ // @ts -ignore just testing
152+ setPluginComponents ( ( prev ) => [ ...prev , newVal ] ) ,
140153 )
141- convertRender ( plugin . render , setPluginComponent )
142154 } ,
143155 }
144156 } ) ,
145157 } ) ,
146158 )
159+
147160 useEffect ( ( ) => {
148161 if ( devToolRef . current ) {
149162 devtools . mount ( devToolRef . current )
@@ -155,11 +168,17 @@ export const TanStackDevtools = ({
155168 return (
156169 < >
157170 < div style = { { position : 'absolute' } } ref = { devToolRef } />
158- { pluginContainer && PluginComponent
159- ? createPortal ( < > { PluginComponent } </ > , pluginContainer )
171+
172+ { pluginContainers . length > 0 && PluginComponents . length > 0
173+ ? pluginContainers . map ( ( pluginContainer , index ) =>
174+ createPortal ( < > { PluginComponents [ index ] } </ > , pluginContainer ) ,
175+ )
160176 : null }
161- { titleContainer && TitleComponent
162- ? createPortal ( < > { TitleComponent } </ > , titleContainer )
177+
178+ { titleContainers . length > 0 && TitleComponents . length > 0
179+ ? titleContainers . map ( ( titleContainer , index ) =>
180+ createPortal ( < > { TitleComponents [ index ] } </ > , titleContainer ) ,
181+ )
163182 : null }
164183 </ >
165184 )
0 commit comments