Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toolbar): Remount toolbar rather than block it #1287

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/polite-donkeys-reflect.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@electric-sql/debug-toolbar": patch
---

Guard against adding toolbar to DOM twice
Allow toolbar to remount properly on consecutive `addToolbar` calls
9 changes: 5 additions & 4 deletions components/toolbar/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ 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)) {
const existingToolbar = document.getElementById(TOOLBAR_CONTAINER_ID)
if (existingToolbar !== null) {
console.warn(
'[@electric-sql/debug-toolbar] Toolbar has already been added.',
'[@electric-sql/debug-toolbar] Toolbar has already been added - remounting.',
)
return
existingToolbar.remove()
}

const toolbarApi = clientApi(electric.registry)
Expand All @@ -124,7 +125,7 @@ export function addToolbar(electric: ElectricClient<any>) {

// add styles to shadow dom
const template = getToolbarTemplate()
shadow.appendChild(template.content)
shadow.appendChild(template.content.cloneNode(true))

// render toolbar to shadow dom
const toolbarDiv = document.createElement('div')
Expand Down
Loading