Skip to content

Commit b88ba42

Browse files
authored
ensure 'afterUnloadDocument' hook is complete before resolving 'storeDocumentHooks' promise (#893)
Co-authored-by: bcarleton3 <bcarleton3@bloomberg.net>
1 parent 4defd26 commit b88ba42

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/server/src/Hocuspocus.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,14 @@ export class Hocuspocus {
530530
() => {
531531
return this.hooks('onStoreDocument', hookPayload)
532532
.then(() => {
533-
this.hooks('afterStoreDocument', hookPayload).then(() => {
533+
this.hooks('afterStoreDocument', hookPayload).then(async () => {
534534
// Remove document from memory.
535535

536536
if (document.getConnectionsCount() > 0) {
537537
return
538538
}
539539

540-
this.unloadDocument(document)
540+
await this.unloadDocument(document)
541541
})
542542
})
543543
.catch(error => {
@@ -589,13 +589,13 @@ export class Hocuspocus {
589589
return chain
590590
}
591591

592-
unloadDocument(document: Document) {
592+
async unloadDocument(document: Document): Promise<any> {
593593
const documentName = document.name
594594
if (!this.documents.has(documentName)) return
595595

596596
this.documents.delete(documentName)
597597
document.destroy()
598-
this.hooks('afterUnloadDocument', { instance: this, documentName })
598+
await this.hooks('afterUnloadDocument', { instance: this, documentName })
599599
}
600600

601601
enableDebugging() {

0 commit comments

Comments
 (0)