Skip to content

Error "s.tagName is undefined" when clicking text node in mjx-break #3461

@devkat

Description

@devkat

Issue Summary

Clicking on text nodes in SVG causes an exception.

Steps to Reproduce:

  1. Render the formula D_i (0 \leq i < n)
  2. Click on the whitespace between the 0 and the \leq character
  3. An exception is thrown: TypeError: can't access property "toLowerCase", s.tagName is undefined

The exception is thrown here:
https://github.com/mathjax/MathJax-src/blob/1a2ef74c0ac0620e7b8de46402c9dce3b95ade52/ts/a11y/explorer/KeyExplorer.ts#L1420

This type assertion casts text nodes to elements:

const nodes = Array.from(clicked.childNodes) as HTMLElement[];

See attached screenshot for the whitespace node in the DOM (inside <mjx-break>).

Technical details:

  • MathJax Version: 4.4.0
  • Client OS: macOS 15.6.1 (24G90)
  • Browser: Firefox 143.0.4 (aarch64)

I am using the following MathJax configuration:

window.MathJax = {
  startup: {
    // Typesetting will be triggered from the React components
    typeset: false,

    pageReady() {
      resolveMathJaxPromise(mathJax);
      return MathJax.startup.defaultPageReady();
    },

    // getComputedStyle returns an empty font size if the node is detached from the DOM
    // https://codeexpert.myjetbrains.com/youtrack/issue/cx-3811/MathJax-crash-in-Safari-26
    // FIXME: remove this once https://github.com/mathjax/MathJax/issues/3458 is fixed
    ready() {
      MathJax.startup.defaultReady();
      MathJax.startup.document.adaptor.fontSize = function (node: Node) {
        const { fontSize }: CSSStyleDeclaration = this.window.getComputedStyle(node);
        return fontSize == null || string.isBlank(fontSize) ? 16 : parseFloat(fontSize);
      };
    },
  },
  loader: {
    load: ['ui/safe'],
    source: {
      '[tex]/amsCd': '[tex]/amscd',
    },
  },
  output: {
    fontPath: `${mathJaxPath}/mathjax-newcm-font`,
  },
  options: {
    safeOptions: {
      allow: {
        //
        //  Values can be "all", "safe", or "none"
        //
        URLs: 'none', // 'none' to prevent cookie theft through external URLs
        classes: 'safe', // safe start with mjx- (can be set by pattern below)
        cssIDs: 'safe', // safe start with mjx- (can be set by pattern below)
        styles: 'safe', // safe are in safeStyles below
      },
      //
      //  Which styles are allowed
      //
      safeStyles: {
        color: true,
        backgroundColor: true,
        border: true,
        cursor: true,
        margin: true,
        padding: true,
        textShadow: true,
        fontFamily: true,
        fontSize: true,
        fontStyle: true,
        fontWeight: true,
        opacity: true,
        outline: true,
      },
      lengthMax: 3, // Largest padding/border/margin, etc. in em's
      scriptsizemultiplierRange: [0.6, 1], // Valid range for scriptsizemultiplier
      scriptlevelRange: [-2, 2], // Valid range for scriptlevel
      classPattern: /^mjx-[-a-zA-Z0-9_.]+$/, // Pattern for allowed class names
      idPattern: /^mjx-[-a-zA-Z0-9_.]+$/, // Pattern for allowed ids
      dataPattern: /^data-mjx-/, // Pattern for data attributes
    },
  },
  tex: {
    inlineMath: [['$', '$']],
    displayMath: [['$$', '$$']],
    processEscapes: true,
  },
};

and loading MathJax via

http://localhost:3020/mathjax/tex-svg.js
Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    AcceptedIssue has been reproduced by MathJax teamCode ExampleContains an illustrative code example, solution, or work-aroundReady for Reviewv4

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions