immerjs / immer

Create the next immutable state by mutating the current one

Home Page:https://immerjs.github.io/immer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Options for older browser support in v10 (or continuing to use v9 somehow?)

glenjamin opened this issue Β· comments

πŸ™‹β€β™‚ Question

I'm currently working on upgrading to RTK 2.0 - which brings with it an upgrade to immer v10.

Our application needs to support older browsers like smart TVs which tend to bundle pretty old versions of chrome, so we continue to compile down to ES5.

Do I have any options for making this work?

I see that v10 dropped support for the ES5 fallback, but it's unclear to me whether I can use polyfills or a v9 override to get around this.

The FAQ entry is rather terse on this point: https://immerjs.github.io/immer/installation/#immer-on-older-javascript-environments

Link to repro

n/a

Environment

We only accept questions against the latest Immer version.

  • Immer version: 9 and 10

Unfortunately this is the "price of progress" :) As tools modernize, they drop support for legacy platforms... and if you still have to support that legacy platform, you can end up stuck and not being able to update.

In this case, yeah, RTK 2.0 intentionally updates to Immer 10, and Immer 10 does not have the ES5 fallback support.

The biggest question is whether those old versions of Chrome have support for Proxies. If they do, then you could at least use Immer 10 and if necessary transpile packages in node_modules (Immer, RTK, etc) back to ES5 syntax.

If those versions of Chrome do not have Proxy support, then you would need to stick with Immer 9. At that point things get more complicated:

  • The simplest option is to stick with RTK 1.9 and Immer 9, since they are already meant to work together, and RTK 1.9 automatically enables the Immer ES5 fallback
  • It might theoretically be possible to install RTK 2.0, use your package manager's override system to install Immer 9, and have that work. You would have to import the enableES5 fallback plugin and call that in your app, since RTK 2.0 no longer does that. I honestly think it might work, but would not be surprised if there's some kind of import/export issue along the way.

Thanks for the quick response!

I'm keen to adopt the selectors-in-slices model, it's a shame that brings with it a bunch of extra complications!

We have various possible plans for finally dropping support, but so far every issue we've run into has had a fairly cheap workaround.

The Smart TVs tend to be a bit mysterious about what they actually support, but I suspect most of them do actually support Proxy, so perhaps I'll get away with this.

Do you know if there are any intentional API changes between 9 and 10 aside from the ES5 compat flag?

Your second suggestion is pretty much what I had in mind to try. Even if there is a small difference I figure I can probably swap in a shim using either the bundler or npm to override.

I'll give this a whirl and report back, hopefully I'll have something that can be added to the docs

Looking at https://github.com/immerjs/immer/releases/tag/v10.0.0 , I don't immediately see any other obvious API changes listed. Worth a shot!