Skip to content

feat(core): Introduce splitEffect, an effect with an untracked effect body. - #68703

Closed
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:explicit-effect
Closed

JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:explicit-effect

Conversation

@JeanMeche

@JeanMeche JeanMeche commented May 12, 2026 •

Copy link
Copy Markdown
Member

This is a mere exploration:

This commit introduces splitEffect, a new reactivity primitive that explicitly
separates the tracking phase from the execution (side-effect) phase.

In a standard effect, all signal reads are automatically tracked as dependencies.
This often forces developers to manually wrap their side-effects in untracked()
to avoid accidentally tracking signals, which causes unnecessary re-evaluations
or circular updates.

splitEffect solves this by accepting two functions:

  1. A tracking function, where dependencies are explicitly read and returned.
  2. An execution function, which receives the values and is guaranteed to run
    in an untracked context.
splitEffect(
    () => {
        val1: tracked1(),
        val2: tracked2(),
    },
    ({val1, val2}) => {
        log.push(val1,val2);

        // This read should not be tracked as a dependency.
        untrackedSignal();
    },
);

fixes #56155

Curious about what the community would think of it.

@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: core Issues related to the framework runtime labels May 12, 2026
@ngbot ngbot Bot modified the milestone: Backlog May 12, 2026
@eneajaho

Copy link
Copy Markdown
Contributor

Let's go!

@JeanMeche
JeanMeche force-pushed the explicit-effect branch 2 times, most recently from 50dd0d0 to 05e7e22 Compare May 12, 2026 21:54
@michael-small

Copy link
Copy Markdown
Contributor

Curious about what the community would think of it

I am routinely caught off guard by effect usage where functions used inside of them have hidden tracked signals. And the implementation of those functions are not always on my end, so I end up cautiously using either untracked or one of the alternatives for explicit tracking that you added to ngxtension (explicitEffect and on for others' reference). I think this would be a nice option to have natively.

@johalternate

johalternate commented May 13, 2026 •

Copy link
Copy Markdown

This would definitely be a nice addition and eliminate the need of being hyper-defensive when writing effects.

@JeanMeche
JeanMeche force-pushed the explicit-effect branch 7 times, most recently from b07bf13 to 6cc5d01 Compare May 22, 2026 17:25
…fect body.

This commit introduces `splitEffect`, a new reactivity primitive that explicitly
separates the tracking phase from the execution (side-effect) phase.

In a standard `effect`, all signal reads are automatically tracked as dependencies.
This often forces developers to manually wrap their side-effects in `untracked()`
to avoid accidentally tracking signals, which causes unnecessary re-evaluations
or circular updates.

`splitEffect` solves this by accepting two functions:
1. A **tracking function**, where dependencies are explicitly read and returned.
2. An **execution function**, which receives the values and is guaranteed to run
   in an untracked context.

```ts
splitEffect(
    () => {
        val1: tracked1(),
        val2: tracked2(),
    },
    ({val1, val2}) => {
        log.push(val1,val2);

        // This read should not be tracked as a dependency.
        untrackedSignal();
    },
);
```

fixes angular#56155
@JeanMeche JeanMeche changed the title feat(core): explicit effect feat(core): Introduce splitEffect, an effect with an untracked effect body. May 22, 2026
@angular-robot

angular-robot Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

This draft PR is being closed because it has been stale for 28 days and has seen no activity from you. If you'd like to see this change land, you can re-open this PR. Thank you for being an Angular contributor!

@angular-robot angular-robot Bot closed this Jun 20, 2026
@angular-automatic-lock-bot

Copy link
Copy Markdown

This pull request has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: core Issues related to the framework runtime detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit Tracking for effect(): Request for Reconsideration

4 participants

Sponsor
SponsoredKunjungi sekarang
Promo