Skip to content

Plugins can't be disabled if error thrown in beforeunload #10107

@AllanChain

Description

@AllanChain

Search first

  • I searched and no similar issues were found

What Happened?

If a plugin has beforeunload hook which throws an error, clicking disable won't really disable the plugin, and the plugin will be enabled again after the app restart.

Reproduce the Bug

  1. Create a simple plugin
index.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Logseq selection bug</title>
</head>
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/@logseq/libs"></script>
<script src="./index.js"></script>
</body>
</html>
package.json
{
  "name": "logseq-unload-bug",
  "version": "1.0.0",
  "description": "",
  "main": "index.html",
  "logseq": {
    "id": "logseq-unload-bug"
  },
  "license": "MIT"
}
index.js
function main () {
  logseq.beforeunload(() => {
    throw "I won't unload!!!"
  })
}

logseq.ready(main).catch(console.error)
  1. Disable the plugin.
  2. Restart app. The plugin is not disabled.

Expected Behavior

The plugin will be disabled despite it throwing an error in beforeunload

Screenshots

No response

Desktop or Mobile Platform Information

Linux, Desktop App, v0.9.15

Additional Context

Maybe just add try{}catch{}?

await this.load()

await this.unload()

Are you willing to submit a PR? If you know how to fix the bug.

  • I'm willing to submit a PR (Thank you!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions