Fix the false-positive error in studio.extend

This removes the `Extension id "${extension.id}" is already defined` error when `studio.extend()` is in a hot-reloaded file but the extension hasn't actually changed.
This commit is contained in:
Aria Minaei 2023-07-28 20:46:32 +02:00 committed by Aria
parent 1280de02d0
commit 5192c42548

View file

@ -275,20 +275,23 @@ export class Studio {
throw new Error(`extension.id must be a string`)
}
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`)
}
const extensionId = extension.id
const prevExtension =
this._store.getState().ephemeral.extensions.byId[extensionId]
if (prevExtension) {
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`)
}
this.transaction(({drafts}) => {
drafts.ephemeral.extensions.byId[extension.id] = extension
const allPaneClasses = drafts.ephemeral.extensions.paneClasses