Skip to content

[Safari] TypeError when reopening math-field after unmounting it while focused #2952

@konbu310

Description

@konbu310

Summary

In Safari, if <math-field> is unmounted while still focused (e.g. closing modal via backdrop), reopening it triggers: TypeError: undefined is not an object (evaluating 'this.mathfield.options').

error.mov

Reproduction

Steps to reproduce

  1. Open the demo in Safari.
  2. Click the formula card to open the editor modal.
  3. Close the modal via backdrop (Not Cancel or OK button).
  4. Open the modal again.
  5. Check the console.

Causes and Workarounds

In Safari, it seems blur() is called after dispose().

Since this.mathfield becomes undefined, it throws a TypeError when trying to read this.mathfield.options.defaultMode.

defaultMode: this.mathfield.options.defaultMode,

Rewriting it to use optional chaining (this.mathfield?.options?.defaultMode ?? "math") avoids the issue, but this feels like a temporary fix. I'd like to know if there's a better solution. (Or ways to workaround it on the client side.)

Environment

  • Browser: Safari (macOS)
  • MathLive: 0.108.3
  • React: 19.2.4
  • The repro uses conditional rendering (mount/unmount) in a modal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions