GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — requestUtils.get calls setRequestHeaders without the request as this · Issue #1245 · maxGraph/maxGraph

requestUtils.get calls setRequestHeaders without the request as this #1245

New issue
Copy link
New issue
Copy link
Open
Bug
Open
requestUtils.get calls setRequestHeaders without the request as this#1245
Bug
Copy link

Description

@redfish4ktc
redfish4ktc
opened on Oct 10, 2026
Issue body actions

Describe the bug

When requestUtils.get is called with headers, it wraps the setRequestHeaders method of the MaxXmlRequest it creates, and calls the original method with this set to undefined instead of the request.

export const get = (url, onload = null, onerror = null, binary = false, timeout = null, ontimeout = null, headers = null) => {
  const req = new MaxXmlRequest(url, null, 'GET');
  const { setRequestHeaders } = req;

  if (headers) {
    req.setRequestHeaders = (request, params) => {
      setRequestHeaders.apply(this, [request, params]);
      // ...

See requestUtils.ts#L79-L106.

Both get and the wrapper are arrow functions, so this is the this of the module, which is undefined in an ES module. In mxGraph, mxUtils.get and the wrapper were regular functions (mxUtils.js#L1552-L1565), so this was the request on which setRequestHeaders is called by send (MaxXmlRequest.ts#L272). The binding was lost when the code was converted to arrow functions.

Impact

The default implementation of MaxXmlRequest.setRequestHeaders (MaxXmlRequest.ts#L311) does not read this, so nothing goes wrong with it today.

It breaks as soon as the method relies on this, for instance when an application overrides MaxXmlRequest.prototype.setRequestHeaders to read a property of the request (this.params, this.url, ...): with headers passed to get, this is undefined in that override, so reading a property of it throws a TypeError.

To Reproduce

This Jest test, run in packages/core, records the this the original setRequestHeaders receives:

import { afterEach, beforeEach, describe, expect, jest, test } from '@jest/globals';
import { MaxXmlRequest, requestUtils } from '../../src';

describe('get', () => {
  beforeEach(() => {
    jest.spyOn(XMLHttpRequest.prototype, 'send').mockImplementation(() => {});
  });

  afterEach(() => {
    jest.restoreAllMocks();
  });

  test.each([
    ['without headers', null],
    ['with headers', { Authorization: 'token xyz' }],
  ])('call setRequestHeaders on the request %s', (_description, headers) => {
    const setRequestHeadersSpy = jest.spyOn(MaxXmlRequest.prototype, 'setRequestHeaders');

    const request = requestUtils.get(
      'diagram.xml',
      null,
      null,
      false,
      null,
      null,
      headers
    );

    expect(setRequestHeadersSpy).toHaveBeenCalledTimes(1);
    expect(setRequestHeadersSpy.mock.contexts[0]).toBe(request);
  });
});

The case without headers passes. The case with headers fails, this being undefined:

● get › call setRequestHeaders on the request with headers
  expect(received).toBe(expected) // Object.is equality
  Expected: {"async": true, "binary": false, ..., "url": "diagram.xml", ...}
  Received: undefined

Replacing this with req in get makes both cases pass.

Expected behavior

The original setRequestHeaders is called with the request as this, as in mxGraph:

setRequestHeaders.apply(req, [request, params]);

This was working with mxGraph.

Environment

  • maxGraph version or commit: 0.25.0, and main at 2e8c755
  • Desktop or mobile: any
  • OS and version: any
  • Browser and version: any

Additional context

Found with the topLevelThis performance hint added in webpack 5.110.0, which reports 1 read of 'this' at the top level of an ES module: ../core/lib/esm/util/requestUtils.js when building the js-example package with performance.all: true.

Activity

  1. redfish4ktc
    added this to the 0.25.1 milestone on Oct 10, 2026
  2. redfish4ktc
    added the
    Bug
    issue type on Oct 10, 2026
  3. redfish4ktc
    modified the milestones: 0.25.1, 0.25.2 on Oct 21, 2026
  4. redfish4ktc
    removed this from the 0.25.2 milestone on Nov 2, 2026
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

    Bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.