diff --git a/__tests__/map-set.js b/__tests__/map-set.js index cdcc5725..8bf726f9 100644 --- a/__tests__/map-set.js +++ b/__tests__/map-set.js @@ -5,7 +5,8 @@ import { original, isDraft, immerable, - enableAllPlugins + enableAllPlugins, + enableMapSet } from "../src/immer" import {each, shallowCopy, isEnumerable, DRAFT_STATE} from "../src/common" @@ -280,5 +281,19 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) { }) expect(result).toBe(set) }) + + test("#692 - idempotent plugin loading", () => { + let mapType1 + produce(new Map(), draft => { + mapType1 = draft.constructor + }) + + enableMapSet() + let mapType2 + produce(new Map(), draft => { + mapType2 = draft.constructor + }) + expect(mapType1).toBe(mapType2) + }) }) } diff --git a/src/utils/plugins.ts b/src/utils/plugins.ts index 539e4c3c..6b2568ab 100644 --- a/src/utils/plugins.ts +++ b/src/utils/plugins.ts @@ -62,7 +62,7 @@ export function loadPlugin( pluginKey: K, implementation: Plugins[K] ): void { - plugins[pluginKey] = implementation + if (!plugins[pluginKey]) plugins[pluginKey] = implementation } /** ES5 Plugin */