Skip to content

Conversation

9romise
Copy link

@9romise 9romise commented Sep 19, 2025

This PR introduces a lazy-initialized signal getter on EffectScope.

  • When scope.signal is accessed for the first time, an AbortController will be created and its AbortSignal returned.
  • If scope.signal is never accessed, no controller will be created, avoiding unnecessary overhead.
  • When scope.stop() is called, if an AbortController exists, it will automatically trigger controller.abort().

Related: #13861 (comment), #13861 (comment)

It would be good to have this for effectScope and watch. This would allow us to get the signal with getCurrentScope.

const {signal} = getCurrentScope()

fetch(url, {signal})

/cc @ferferga, @OrbisK, @antfu

@OrbisK
Copy link
Contributor

OrbisK commented Sep 19, 2025

Someday, we could follow up on this by merging the effects signal with its parent signals (AbortSignal.any()), which would remove the need for the cleanup array + loop. (Should be benchmarked)

for (i = 0, l = this.cleanups.length; i < l; i++) {
this.cleanups[i]()
}
this.cleanups.length = 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants