Skip to content

Dialog and BottomSheet plugins: hide() throws a TypeError once the dialog has been dismissed #18615

Backlog

Description

@officialasishkumar

What happened?

Calling hide() on the object returned by $q.dialog() or $q.bottomSheet() throws once the dialog has already been dismissed:

Uncaught (in promise) TypeError: Cannot read properties of null (reading '$')

When the dialog hides, onHide in ui/src/utils/private.dialog/create-dialog.js unmounts the child app and sets vm = null, and Vue clears dialogRef. A later hide() goes through applyState('hide'), which finds no dialogRef.value and falls back to walking vm.$.subTree on the released vm. update() on the same object already checks vm !== null and does nothing in this state. hide() has no such check.

This comes up whenever app code hides a dialog that the user may already have closed. A typical case is a try/finally around an async task, or a route-leave hook:

const dialog = $q.dialog({ message: 'Saving...', progress: true, ok: false })

try {
  await save()
} finally {
  dialog.hide() // throws if the user pressed ESC / clicked the backdrop meanwhile
}

The TypeError comes out of the finally block and replaces the result of save(). The caller sees a crash even when the save succeeded.

What did you expect to happen?

hide() should do nothing when the dialog is already gone, the same way update() does, and still return the chain object.

Reproduction URL

Self-contained HTML below (Vue 3 and Quasar 2.36.0 UMD from jsDelivr)

How to reproduce?

<!DOCTYPE html>
<html>
<head>
  <link href="https://cdn.jsdelivr.net/npm/quasar@2.36.0/dist/quasar.prod.css" rel="stylesheet">
</head>
<body>
  <div id="app">
    <q-btn label="Save" color="primary" @click="save"></q-btn>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/quasar@2.36.0/dist/quasar.umd.prod.js"></script>
  <script>
    const app = Vue.createApp({
      setup() {
        const $q = Quasar.useQuasar()

        async function save() {
          const dialog = $q.dialog({ message: 'Saving...', progress: true, ok: false })

          try {
            await new Promise(resolve => setTimeout(resolve, 3000))
          } finally {
            dialog.hide()
          }
        }

        return { save }
      }
    })
    app.use(Quasar)
    app.mount('#app')
  </script>
</body>
</html>
  1. Open the page and click "Save".
  2. Press ESC (or click the backdrop) within 3 seconds.
  3. When the 3 seconds are up, the console shows the TypeError above.

$q.bottomSheet() behaves the same, since both plugins share createDialog().

Flavour

UMD

Platforms/Browsers

Chrome

Versions

quasar 2.36.0 (same code on dev), vue 3.5

Relevant log output

Uncaught (in promise) TypeError: Cannot read properties of null (reading '$')

Additional context

It does not depend on the flavour or the browser: it is a null dereference in createDialog(). The UMD page above is only the shortest way to reproduce it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions