Skip to content

Commit

Permalink
fix(toolbar): Guard against adding toolbar to DOM twice (#1280)
Browse files Browse the repository at this point in the history
Checks whether container element has already been added before
proceeding to add toolbar.

With React's `StrictMode` and other cases the `addToolbar` call might
occur twice, handling it with a warning I believe is better than letting
it add a broken DOM element.
  • Loading branch information
msfstef committed May 20, 2024
1 parent 875200b commit f4af7f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-donkeys-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@electric-sql/debug-toolbar": patch
---

Guard against adding toolbar to DOM twice
7 changes: 7 additions & 0 deletions components/toolbar/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ export function clientApi(registry: GlobalRegistry | Registry) {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function addToolbar(electric: ElectricClient<any>) {
if (document.getElementById(TOOLBAR_CONTAINER_ID)) {
console.warn(
'[@electric-sql/debug-toolbar] Toolbar has already been added.',
)
return
}

const toolbarApi = clientApi(electric.registry)

const containerDiv = document.createElement('div')
Expand Down

0 comments on commit f4af7f6

Please sign in to comment.