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

Error: Failed to execute 'transaction' on 'IDBDatabase' while changing routes #220

Closed
fayeed opened this issue Aug 23, 2021 · 15 comments
Closed
Labels
bug Something isn't working

Comments

@fayeed
Copy link

fayeed commented Aug 23, 2021

While changing routes I get this error DOMException: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.

I am using this inside web component which is then imported inside a Vue app, app/ component is not crashing or anything just seeing this as an error log.

@nolanlawson
Copy link
Owner

What browser/OS are you seeing this in? When you say "changing routes," what do you mean exactly? Are you changing routes in a multi-page app or single-page app – i.e. are these actual page navigations, or in-app pseudo-navigations?

I'm not sure it helps, but you may want to look into the Page Lifecycle API. In particular, in the section on the "frozen" event, note that it recommends "Close all open IndexedDB connections." In emoji-picker-element this can be accomplished with:

document.querySelector('emoji-picker').database.close()

@nolanlawson nolanlawson added the bug Something isn't working label Aug 26, 2021
@nolanlawson
Copy link
Owner

Related discussion: jensarps/IDBWrapper#80

@fayeed
Copy link
Author

fayeed commented Aug 26, 2021

Hi Nolan, We have a web component library where we use this package and then use it inside an electron app which has a Vue app, it's a SPA. So what happens is that when we change the route I see the error in the logs.

@nolanlawson
Copy link
Owner

nolanlawson commented Aug 26, 2021

I see, so it's Chromium and this is an in-SPA pseudo-navigation. So I imagine the <emoji-picker> is getting unmounted from the DOM and closing the database connection.

Do you have a stacktrace? Or is it just the single warning message in the console?

Also I found a Chrome bug: https://crbug.com/1085724

@fayeed
Copy link
Author

fayeed commented Aug 26, 2021

I see, so it's Chromium and this is an in-SPA pseudo-navigation. So I imagine the is getting unmounted from the DOM and closing the database connection.

Yeah I think so

Do you have a stacktrace? Or is it just the single warning message in the console?

Unfortunately no, it's just a single warning

@fayeed
Copy link
Author

fayeed commented Aug 26, 2021

Thanks for the help though I will try out some suggestions that you made and get back to you.

@fayeed
Copy link
Author

fayeed commented Aug 26, 2021

@nolanlawson Manually closing the database before changing the route fixed the issue. Thanks for all the help.

@nolanlawson
Copy link
Owner

Sounds good! Thanks.

@vmartinBT
Copy link

What browser/OS are you seeing this in? When you say "changing routes," what do you mean exactly? Are you changing routes in a multi-page app or single-page app – i.e. are these actual page navigations, or in-app pseudo-navigations?

I'm not sure it helps, but you may want to look into the Page Lifecycle API. In particular, in the section on the "frozen" event, note that it recommends "Close all open IndexedDB connections." In emoji-picker-element this can be accomplished with:

document.querySelector('emoji-picker').database.close()

This worked for me. Thanks!

@ekimber
Copy link

ekimber commented Jan 13, 2023

This does not work for me. Looks like the component gets unmounted by react before the database close function completes. Any suggestions?

@nolanlawson
Copy link
Owner

@ekimber Can you call database.close() (as described above) before the component unmounts?

@ekimber
Copy link

ekimber commented Jan 14, 2023

@ekimber Can you call database.close() (as described above) before the component unmounts?

I can call it before it unmounts, however, it is of course async, and from what I can observe, the unmount is occurring before the close promise completes

@ekimber
Copy link

ekimber commented Jan 14, 2023

Actually that may be wrong. I tried pausing execution there but it doesn't help.
Here is the stack trace:

    at eval (http://localhost:8280/_js/compiled/cljs-runtime/module$node_modules$emoji_picker_element$database.js:4:118)
    at new Promise (<anonymous>)
    at dbPromise (http://localhost:8280/_js/compiled/cljs-runtime/module$node_modules$emoji_picker_element$database.js:4:74)
    at get (http://localhost:8280/_js/compiled/cljs-runtime/module$node_modules$emoji_picker_element$database.js:14:68)
    at eval (http://localhost:8280/_js/compiled/cljs-runtime/module$node_modules$emoji_picker_element$database.js:9:76)
    at Array.map (<anonymous>)
    at hasData (http://localhost:8280/_js/compiled/cljs-runtime/module$node_modules$emoji_picker_element$database.js:9:67)
    at checkForUpdates (http://localhost:8280/_js/compiled/cljs-runtime/module$node_modules$emoji_picker_element$database.js:23:421)```

@nolanlawson
Copy link
Owner

You might need to do an unhandled rejection event listener or something.

database.close().catch(() => {}) may also work. This is a good blog post on the subject: https://jakearchibald.com/2023/unhandled-rejections/

@ekimber
Copy link

ekimber commented Jan 17, 2023

Thanks, I managed to get rid of the warning by doing this database.close().catch(() => {})
I have to do it as soon as the component is mounted. Odd, but it still seems to function ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants