Skip to content

Calling enablePluginName() is not idempotent#692

Description

@blixt

馃悰 Bug Report

Calling enableMapSet() multiple times results in the work of adding Map and Set support being performed every time. It should only be performed the first time so that big codebases with multiple entrypoints and tests can safely call it in the parts of the code that knows the feature will be used, without having to worry about other parts of the codebase having already called it.

Link to repro

https://codesandbox.io/s/immer-sandbox-forked-q2pu1?file=/src/index.ts

To Reproduce

Have a big codebase that may call enableMapSet in different modules that are used by different entrypoints, but it's very hard to predict in the entrypoint which modules will be used.

Observed behavior

The Map and Set types of immer are patched every time enableMapSet() is called.

Expected behavior

The second call to enableMapSet() should be a no-op.

Environment

We only accept bug reports against the latest Immer version.

  • Immer version:
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions