mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

"Error: can't serialize object of unregistered class" in cypress

Open pburkindine opened this issue 7 years ago • 13 comments

mapbox-gl-js version: 1.0.0

cypress version 3.3.1/3.3.0 - ref: https://github.com/cypress-io/cypress/issues/4322

browser: Electron 61

Steps to Trigger Behavior

  1. Minimal repro available here: https://github.com/pburkindine/mapboxgl-electron/
  2. run npm run start and npm run cy
  3. cypress test will fail; click on failed XHR calls to see stack trace
  • Does not occur in Chrome testing with cypress
  • Does not occur in Electron without cypress (e.g., in electron in cypress, window.location.href="http://localhost:8080" twice)
  • Does not occur in normal use
  • Class in question appears to be ArrayBuffer

Link to Demonstration

https://github.com/pburkindine/mapboxgl-electron/

Expected Behavior

Cypress test should succeed

Actual Behavior

Cypress test fails with error "Error: can't serialize object of unregistered class" in the mapbox webworker

pburkindine avatar May 28 '19 16:05 pburkindine

Hi, sorry you're having trouble. Can you confirm whether or not this worked before, and what version combo (mapbox-gl-js version, cypress version, electron version)?

We fixed an issue in the past with Chrome that sounded similar, but I don't think we've regressed that fix. Lemme know if this helps you (fix was related to thrown Error type on a request abort).

If you can confirm (or deny, that's fine) a version combo that used to work I'd be happy to look into this further.

ahk avatar May 29 '19 19:05 ahk

@ahk thanks, I did see that issue, but not sure if it's related.

I was able to bisect, the repro works fine w/ cypress 3.3.1/electron 61/mapbox 0.52.0 and not with 0.53.0

(maybe worth mentioning that mapbox is pulled from the cdn in public/index.html, not from node_modules, in the repro)

pburkindine avatar May 29 '19 21:05 pburkindine

@ahk just checking on this one

pburkindine avatar Jun 13 '19 17:06 pburkindine

I've been experiencing this issue myself, and have taken a look:

The web worker's serialize function currently checks for ArrayBuffers like so:

https://github.com/mapbox/mapbox-gl-js/blob/94598e70cffbcf239c76259da6351f751062fcc2/src/util/web_worker_transfer.js#L129

However any cypress ArrayBuffer is not guaranteed to test true with instanceof ArrayBuffer, as cypress and many of the packages used by cypress do not test for ArrayBuffer with exclusively instanceof, for the reasons described here. They favour solutions such as:

// ArrayBuffers from another context (i.e. an iframe) do not pass the instanceof check
// but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
function isArrayBuffer (obj) {
  return obj instanceof ArrayBuffer ||
    (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
      typeof obj.byteLength === 'number')
}

I suggest the ArrayBuffer test is updated to account for this. ~~Happy to work on a PR for this.~~

EDIT: Taken a closer look, this might not be so simple due to the static typing. I'm unfamiliar with Flow, and don't know where to proceed from here.

corinv avatar Jul 05 '19 00:07 corinv

@ahk bump

pburkindine avatar Jul 08 '19 16:07 pburkindine

@anthony-hull is this issue resolved?

pburkindine avatar Aug 21 '19 13:08 pburkindine

I haven't tried since the 15th July. We pivoted away from using Cypress when we encountered the error

anthony-hull avatar Aug 21 '19 13:08 anthony-hull

this problem exists if you make a copy of the pencil style and try to use it. copies of minimo seem to work fine.

worc avatar Oct 10 '19 08:10 worc

this problem exists if you make a copy of the pencil style and try to use it. copies of minimo seem to work fine.

@worc this is caused by a new feature in 1.4 which wasn't registered properly. we're working on a 1.4.1 patch which will include a fix for this issue. unfortunately, the broader ticket here isn't related and won't be fixed by 1.4.1

ryanhamley avatar Oct 10 '19 18:10 ryanhamley

This will be fixed by https://github.com/mapbox/mapbox-gl-js/pull/8868

kkaefer avatar Oct 14 '19 15:10 kkaefer

This will be fixed by #8868

Are users recommended to wait for mapbox-gl 1.6.0 to come out to fix this?

Tehsurfer avatar Oct 22 '19 02:10 Tehsurfer

@Tehsurfer No, it will be part of the upcoming 1.5.0 release later this week or early next week.

kkaefer avatar Oct 22 '19 08:10 kkaefer

You can check out 1.5.0-beta.1 meanwhile

kkaefer avatar Oct 22 '19 08:10 kkaefer