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:
parent
1280de02d0
commit
5192c42548
1 changed files with 16 additions and 13 deletions
|
@ -275,20 +275,23 @@ export class Studio {
|
||||||
throw new Error(`extension.id must be a string`)
|
throw new Error(`extension.id must be a string`)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.transaction(({drafts}) => {
|
const extensionId = extension.id
|
||||||
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 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
|
drafts.ephemeral.extensions.byId[extension.id] = extension
|
||||||
|
|
||||||
const allPaneClasses = drafts.ephemeral.extensions.paneClasses
|
const allPaneClasses = drafts.ephemeral.extensions.paneClasses
|
||||||
|
|
Loading…
Reference in a new issue