Skip to content

Commit

Permalink
fix: race condition in client.listen memory leak (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored May 13, 2024
1 parent d9c832d commit d2e468a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sanity/client",
"version": "6.18.0",
"version": "6.18.1-canary.0",
"description": "Client for retrieving, creating and patching data from Sanity.io",
"keywords": [
"sanity",
Expand Down
4 changes: 4 additions & 0 deletions src/data/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
.then((eventSource) => {
if (eventSource) {
es = eventSource
// Handle race condition where the observer is unsubscribed before the EventSource is set up
if (unsubscribed) {
unsubscribe()
}
}
})
.catch((reason) => {
Expand Down

0 comments on commit d2e468a

Please sign in to comment.