From c4862ee6ef7d8cea91d8acda4f19b8618298b7a7 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Sat, 17 Sep 2022 19:44:19 +0200 Subject: [PATCH] Allow re-registering the exact same extension --- theatre/studio/src/Studio.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/theatre/studio/src/Studio.ts b/theatre/studio/src/Studio.ts index 7ab6fdb..3e43449 100644 --- a/theatre/studio/src/Studio.ts +++ b/theatre/studio/src/Studio.ts @@ -22,6 +22,7 @@ import type {Deferred} from '@theatre/shared/utils/defer' import {defer} from '@theatre/shared/utils/defer' import type {ProjectId} from '@theatre/shared/utils/ids' import checkForUpdates from './checkForUpdates' +import shallowEqual from 'shallowequal' export type CoreExports = typeof _coreExports @@ -223,6 +224,15 @@ export class Studio { this.transaction(({drafts}) => { if (drafts.ephemeral.extensions.byId[extension.id]) { + const prevExtension = drafts.ephemeral.extensions.byId[extension.id] + if ( + extension === prevExtension || + shallowEqual(extension, prevExtension) + ) { + // probably running studio.extend() several times because of hot reload. + // as long as it's the same extension, we can safely ignore. + return + } throw new Error(`Extension id "${extension.id}" is already defined`) }