Skip to content

Commit ba864ad

Browse files
authored
build: update distribution (#3154)
1 parent b57f967 commit ba864ad

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

dist/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -31563,8 +31563,9 @@ const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.versi
3156331563
let registry
3156431564

3156531565
if (hasFinalizationRegistry) {
31566-
registry = new FinalizationRegistry((stream) => {
31567-
if (!stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
31566+
registry = new FinalizationRegistry((weakRef) => {
31567+
const stream = weakRef.deref()
31568+
if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
3156831569
stream.cancel('Response object has been garbage collected').catch(noop)
3156931570
}
3157031571
})
@@ -32055,7 +32056,12 @@ function fromInnerResponse (innerResponse, guard) {
3205532056
setHeadersGuard(response[kHeaders], guard)
3205632057

3205732058
if (hasFinalizationRegistry && innerResponse.body?.stream) {
32058-
registry.register(response, innerResponse.body.stream)
32059+
// If the target (response) is reclaimed, the cleanup callback may be called at some point with
32060+
// the held value provided for it (innerResponse.body.stream). The held value can be any value:
32061+
// a primitive or an object, even undefined. If the held value is an object, the registry keeps
32062+
// a strong reference to it (so it can pass it to the cleanup callback later). Reworded from
32063+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
32064+
registry.register(response, new WeakRef(innerResponse.body.stream))
3205932065
}
3206032066

3206132067
return response

0 commit comments

Comments
 (0)