Skip to content

Commit

Permalink
Bugfix:dexie-cloud def.GUI fail if incl. in <head>
Browse files Browse the repository at this point in the history
If dexie-cloud-addon is included in <head> before <body> is rendered,
the default login GUI fails to load.
  • Loading branch information
dfahlander committed Oct 17, 2022
1 parent d9fd2ab commit 949d233
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions addons/dexie-cloud/src/default-ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,24 @@ export default class LoginGui extends Component<Props, State> {
}

export function setupDefaultGUI(db: Dexie) {
const el = document.createElement('div');
document.body.appendChild(el);
preact.render(<LoginGui db={db.vip} />, el);

let closed = false;

const el = document.createElement('div');
if (document.body) {
document.body.appendChild(el);
preact.render(<LoginGui db={db.vip} />, el);
} else {
addEventListener('DOMContentLoaded', ()=>{
if (!closed) {
document.body.appendChild(el);
preact.render(<LoginGui db={db.vip} />, el);
}
});
}

return {
unsubscribe() {
el.remove();
try { el.remove(); } catch {}
closed = true;
},
get closed() {
Expand Down

0 comments on commit 949d233

Please sign in to comment.