Skip to content

Commit 4dfd562

Browse files
feat: add devtools utils to pacer (#80)
* feat: add devtools utils to pacer * update lock * ci: apply automated fixes * fix2 * changeset --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent f901a93 commit 4dfd562

File tree

18 files changed

+99
-157
lines changed

18 files changed

+99
-157
lines changed

.changeset/shaggy-kiwis-walk.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@tanstack/react-pacer-devtools': patch
3+
'@tanstack/solid-pacer-devtools': patch
4+
'@tanstack/pacer-devtools': patch
5+
---
6+
7+
update pacer devtools to use devtools-utils to avoid common issues in user projects

packages/pacer-devtools/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@tanstack/devtools-ui": "^0.3.5",
66+
"@tanstack/devtools-utils": "^0.0.3",
6667
"@tanstack/solid-store": "^0.7.7",
6768
"clsx": "^2.1.1",
6869
"dayjs": "^1.11.18",
Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,10 @@
1+
import { constructCoreClass } from '@tanstack/devtools-utils/solid'
12
import { lazy } from 'solid-js'
2-
import { Portal, render } from 'solid-js/web'
33

4-
export interface PacerDevtoolsInit {}
5-
6-
export class PacerDevtoolsCore {
7-
#isMounted = false
8-
#dispose?: () => void
9-
#Component: any
10-
#ThemeProvider: any
4+
const Component = lazy(() => import('./PacerDevtools'))
115

12-
constructor(_init?: PacerDevtoolsInit | undefined) {}
13-
14-
mount<T extends HTMLElement>(el: T, theme: 'light' | 'dark') {
15-
if (this.#isMounted) {
16-
throw new Error('Devtools is already mounted')
17-
}
18-
const mountTo = el
19-
const dispose = render(() => {
20-
this.#Component = lazy(() => import('./PacerDevtools'))
21-
const Devtools = this.#Component
22-
this.#ThemeProvider = lazy(() =>
23-
import('@tanstack/devtools-ui').then((mod) => ({
24-
default: mod.ThemeContextProvider,
25-
})),
26-
)
27-
const ThemeProvider = this.#ThemeProvider
6+
export interface PacerDevtoolsInit {}
287

29-
return (
30-
<Portal mount={mountTo}>
31-
<div style={{ height: '100%' }}>
32-
<ThemeProvider theme={theme}>
33-
<Devtools />
34-
</ThemeProvider>
35-
</div>
36-
</Portal>
37-
)
38-
}, mountTo)
39-
this.#isMounted = true
40-
this.#dispose = dispose
41-
}
8+
const [PacerDevtoolsCore, PacerDevtoolsCoreNoOp] = constructCoreClass(Component)
429

43-
unmount() {
44-
if (!this.#isMounted) {
45-
throw new Error('Devtools is not mounted')
46-
}
47-
this.#dispose?.()
48-
this.#isMounted = false
49-
}
50-
}
10+
export { PacerDevtoolsCore, PacerDevtoolsCoreNoOp }

packages/pacer-devtools/src/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
import * as Devtools from './core'
44

5-
// Create a dummy class for production that does nothing
6-
class DummyPacerDevtoolsCore {
7-
constructor() {}
8-
mount() {}
9-
unmount() {}
10-
}
11-
12-
export const PacerDevtoolsCore: (typeof Devtools)['PacerDevtoolsCore'] =
5+
export const PacerDevtoolsCore =
136
process.env.NODE_ENV !== 'development'
14-
? (DummyPacerDevtoolsCore as any)
7+
? Devtools.PacerDevtoolsCoreNoOp
158
: Devtools.PacerDevtoolsCore
169

1710
export type { PacerDevtoolsInit } from './core'
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use client'
22

3-
import * as Devtools from './core'
4-
5-
export const PacerDevtoolsCore = Devtools.PacerDevtoolsCore
3+
export { PacerDevtoolsCore } from './core'
64

75
export type { PacerDevtoolsInit } from './core'

packages/react-pacer-devtools/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"react-dom": ">=16.8"
6666
},
6767
"dependencies": {
68+
"@tanstack/devtools-utils": "^0.0.3",
6869
"@tanstack/pacer-devtools": "workspace:*"
6970
},
7071
"devDependencies": {
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
import React, { useEffect, useRef, useState } from 'react'
1+
import { createReactPanel } from '@tanstack/devtools-utils/react'
22
import { PacerDevtoolsCore } from '@tanstack/pacer-devtools'
3+
import type { DevtoolsPanelProps } from '@tanstack/devtools-utils/react'
34

4-
export interface PacerDevtoolsReactInit {
5-
theme?: 'light' | 'dark'
6-
}
5+
export interface PacerDevtoolsReactInit extends DevtoolsPanelProps {}
76

8-
export const PacerDevtoolsPanel = (props?: PacerDevtoolsReactInit) => {
9-
const devToolRef = useRef<HTMLDivElement>(null)
7+
const [PacerDevtoolsPanel, PacerDevtoolsPanelNoOp] =
8+
createReactPanel(PacerDevtoolsCore)
109

11-
const [devtools] = useState(() => new PacerDevtoolsCore({}))
12-
useEffect(() => {
13-
if (devToolRef.current) {
14-
devtools.mount(devToolRef.current, props?.theme ?? 'dark')
15-
}
16-
17-
return () => devtools.unmount()
18-
}, [devtools, props?.theme])
19-
20-
return <div style={{ height: '100%' }} ref={devToolRef} />
21-
}
10+
export { PacerDevtoolsPanel, PacerDevtoolsPanelNoOp }
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
'use client'
22

3-
import React from 'react'
43
import * as Devtools from './ReactPacerDevtools'
4+
import * as plugin from './plugin'
55

6-
export const PacerDevtoolsPanel: (typeof Devtools)['PacerDevtoolsPanel'] =
6+
export const PacerDevtoolsPanel =
77
process.env.NODE_ENV !== 'development'
8-
? function () {
9-
return React.createElement('div')
10-
}
8+
? Devtools.PacerDevtoolsPanelNoOp
119
: Devtools.PacerDevtoolsPanel
1210

13-
export { pacerDevtoolsPlugin } from './plugin'
11+
export const pacerDevtoolsPlugin =
12+
process.env.NODE_ENV !== 'development'
13+
? plugin.pacerDevtoolsNoOpPlugin
14+
: plugin.pacerDevtoolsPlugin
1415

1516
export type { PacerDevtoolsReactInit } from './ReactPacerDevtools'

packages/react-pacer-devtools/src/plugin-prod.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import React from 'react'
2-
import { PacerDevtoolsPanel } from './index'
1+
import { createReactPlugin } from '@tanstack/devtools-utils/react'
2+
import { PacerDevtoolsPanel } from './ReactPacerDevtools'
33

4-
export function pacerDevtoolsPlugin() {
5-
return {
6-
name: 'TanStack Pacer',
7-
render: (_el: HTMLElement, theme: 'light' | 'dark') => {
8-
return <PacerDevtoolsPanel theme={theme} />
9-
},
10-
}
11-
}
4+
const [pacerDevtoolsPlugin, pacerDevtoolsNoOpPlugin] = createReactPlugin(
5+
'TanStack Pacer',
6+
PacerDevtoolsPanel,
7+
)
8+
9+
export { pacerDevtoolsPlugin, pacerDevtoolsNoOpPlugin }

0 commit comments

Comments
 (0)