Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immer 10 proposals: Drop promises, default export, array.length patches, ES5 mode, and make getter / setter support opt-in #1015

Closed
10 of 13 tasks
mweststrate opened this issue Jan 20, 2023 · 14 comments
Labels

Comments

@mweststrate
Copy link
Collaborator

mweststrate commented Jan 20, 2023

馃殌 Feature Proposal

Hi folks,

I've collected a bunch of issues that are together I think worthy of being put in a separate major version:

Notes to self:

  • TS 5
  • verify all error codes still in use
  • clean up old language constructions, iterators etc
  • communicate that Immer now expects Symbol / Map / Set / Proxy to be present in env
  • update size & perf tables
  • chinese translation update
  • errors -> array

cc @markerikson

@markerikson
Copy link
Contributor

@mweststrate AWESOME, great to see this! It aligns wonderfully with the work I'm doing on RTK 2.0.

These all sound like pretty good proposals to me. And yeah, both the default export and ESM things seem like things to put into a major.

Actually, looking at Immer's current package.json, it seems like you already technically are using ESM with the "fix" in 9.0.14 by having both exports and module.

Along with the getter/setter stuff, I wonder if there's any other ideas that could be borrowed from https://github.com/giusepperaso/structura.js or https://github.com/unadlib/mutative to help improve perf?

@oriSomething
Copy link
Contributor

I agree with all points.
About Node ESM, if it's instead of CJS, I'm okay 馃槣. But you do need to know, that if there is a Node application that uses both cjs and esm, it means that if in esm mode for example there was a call for enableMapSet() it won't affect cjs files if you export it to 2 js files, that all the different is module.exports vs export {鈥. So this needs to be done with caution 鈿狅笍

@markerikson
Copy link
Contributor

Yeah, fortunately with RTK we don't have anything stateful that way. I know I've read some articles that have tricks for a file that can be used simultaneously with ESM and CJS imports and correctly share state between (ie, the module is only loaded once despite being loaded in two different ways).

@markerikson
Copy link
Contributor

@mweststrate : just out of curiosity, what would be your estimate for the amount of work involved and a vague ETA for releasing Immer 10? No rush, just trying to get a sense of how that would tie into RTK 2.0. (Which will take us a while to get done, trust me :) )

@mweststrate
Copy link
Collaborator Author

@markerikson my current plan is to work on this 2nd half of March and hopefully release early April.

@childrentime
Copy link
Contributor

bunchee, it can simplify esm/cjs export bundle, used by swr.

@skratchdot
Copy link

skratchdot commented Mar 29, 2023

regarding the Drop the default export work: my project uses eslint and i just upgraded from 8.36.0 to 8.37.0 today, and i started seeing a bunch of warnings:

warning  Using exported name 'produce' as identifier for default export  import/no-named-as-default

what's weird is nothing w/ the eslint-plugin-import plugin changed, and i don't see anything related to that rule changing in my updates today (but maybe something w/ the eslint parsing changed which made the new warning show up)? 馃し

all i had to do was change:

import produce from 'immer';

to:

import { produce } from 'immer';

in a global search/replace.

it was easy to fix, but i wanted to give a heads up here!

also: i'm only mentioning here b/c we might want to update the examples/docs as part of the Drop the default export changes. For example:
https://immerjs.github.io/immer/produce

still uses the "default import".

@einarq
Copy link

einarq commented Apr 5, 2023

Tried out RTK 2 alpha, which includes Immer 10 under the hood, and noticed that delete obj.prop['some-prop'] now fails if delete obj.prop['some-prop'] is undefined.

Known issue? Easy to work around, but works fine in plain js.

@mweststrate
Copy link
Collaborator Author

@einarq there isn't an intentional change there, but if you have a minimal repo or unit test for that that'd be great.

@einarq
Copy link

einarq commented Apr 6, 2023

@skratchdot
Copy link

skratchdot commented Apr 6, 2023

@einarq / @markerikson - curious if changing:

delete state.assigned_[prop]

from:

delete state.assigned_[prop]

to:

delete state?.assigned_?.[prop]

and:

if (state.copy_) delete state.copy_[prop]

from:

delete state.copy_[prop]

to:

delete state?.copy_?.[prop]

will fix this?

i might attempt a fix/pr (and add a unit test)

EDIT: pr is here: #1031

@mweststrate
Copy link
Collaborator Author

@skratchdot, thanks for that! Sorry, missed the PR before from my spotty train connection, but can confirm the issue has been reproduced and fixed, and will be part of the final release

1 similar comment
@mweststrate
Copy link
Collaborator Author

@skratchdot, thanks for that! Sorry, missed the PR before from my spotty train connection, but can confirm the issue has been reproduced and fixed, and will be part of the final release

@mweststrate
Copy link
Collaborator Author

Immer 10 released couple of week ago :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants