es6-shim icon indicating copy to clipboard operation
es6-shim copied to clipboard

Array.find not working in all cases

Open belugabob opened this issue 9 years ago • 6 comments

I'm using es6-shim to polyfill Array.find for broswers that don't support it. The issue that I'm having is that some arrays are not being polyfilled. Further investigation reveals that arrays which I create in my own code are being polyfilled, but arrays withing object structures being sent to the browser via signalr (2.2.0) are not. Is this a known issue, or am I being stupid, and misunderstanding something?

Internet Explorer 11.0.9600.18314 - update 11.0.31 es6-shim 0.35.0

belugabob avatar Jul 15 '16 13:07 belugabob

@belugabob can you explain "arrays with object structures"? I'm not familiar with signalr, but if you try Array.isArray(foo), then unless it returns true, it's not actually an array.

ljharb avatar Jul 15 '16 17:07 ljharb

Forgive my typo - should read "arrays within object structures"

Off the top of my head, as I'm not at my computer, and abbreviated for simplicity...

{ Category: "Staff", Entrants: [ { Name: "Fred", Id: 1},{ Name: "Bert", Id: 2}], }

SignalR is a server to browser communication library which effectively"pushes" data to the browser. I suspect that my issue is related to the way that SignalR deserializes the JSON payload When I get back to my desk, I'll investigate the Array.isArray situation, but I'm pretty sure that 'Entrants' was showing up as an Array, in the browser debugger

belugabob avatar Jul 15 '16 19:07 belugabob

It is possible, if SignalR is creating those arrays in a different realm (like an iframe, or a web worker) then they'd have an un-shimmed Array.prototype. If so, you could use Array.prototype.find.call instead, or, also run the es6-shim in the realm they're using.

ljharb avatar Jul 15 '16 22:07 ljharb

Ok, that sounds possible - will investigate further

belugabob avatar Jul 16 '16 06:07 belugabob

I've the encountered this exact same issue using SignalR 2.2.1.

But this seems to be more of an SignalR issue rather than es6-shim correct?

cvanleeuwen avatar Oct 05 '16 11:10 cvanleeuwen

@cvanleeuwen yes, that seems to be the case. An issue should be filed on SignalR, and this one closed.

ljharb avatar Oct 05 '16 15:10 ljharb