Skip to content

feat(core): split tracking for effect and afterRenderEffect - #68908

Closed
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:split-tracking
Closed

JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:split-tracking

Conversation

@JeanMeche

Copy link
Copy Markdown
Member

Mere investigation / WIP:

Introduce a splitTracking helper to separate reactive tracking from non-reactive effect execution by isolating the reactive logic into a dedicated function.

fixes #56155

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

JeanMeche commented May 24, 2026 •

Copy link
Copy Markdown
Member Author

Usages:

effect:

effect(
  splitTracking(
    () => trackedValue(),
    (val: string, onCleanup: EffectCleanupRegisterFn) => {
      onCleanup(() => ... );
    },
  ),
);

Single phase afterRenderEffect:

afterRenderEffect(
  splitTracking(
    () => trackedValue(),
    (val: string) => {
      untrackedValue();
      effectCount++;
    },
  ),
);

afterRenderEffect with phases

afterRenderEffect({
  earlyRead: () => {
    // early read is tracked
    trackedValue();
    return 42;
  },
  write: splitTracking(
    // tracking fn
    () => trackedValue(),
    (val: string, earlyReadVal: Signal<number>, onCleanup: EffectCleanupRegisterFn) => {
      // non tracking execute fn
      untrackedValue();
      onCleanup(() => { ...  });
    },
  ),
});

@JeanMeche

Copy link
Copy Markdown
Member Author

If we had to compare this PR with #68703, we could argue that a helper function is more versitale to achieve the wanted feature.

Introduce a `splitTracking` helper to separate reactive tracking from non-reactive effect execution by isolating the reactive logic into a dedicated function.

fixes angular#56155
@github-actions

Copy link
Copy Markdown

Deployed adev-preview for 62aeb53 to: https://ng-dev-previews-fw--pr-angular-angular-68908-adev-prev-ew8w3fts.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

@angular-robot

angular-robot Bot commented Jun 22, 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 22, 2026
@JeanMeche JeanMeche reopened this Jul 6, 2026
@AymericB305

Copy link
Copy Markdown

What if an effect looked like a resource:

effect({
  tracked: () => trackedValue(),
  untracked: (val: string, onCleanup: EffectCleanupRegisterFn) => {
    onCleanup(() => ... );
  },
});

Maybe this could be an alternative way of writing it alongside the existing one. I'm not a huge fan of "splitTracking" name, sounds like you are tracking different things at once and handling them separately

@JeanMeche
JeanMeche marked this pull request as ready for review July 14, 2026 13:42
@pullapprove
pullapprove Bot requested review from atscott and crisbeto July 14, 2026 13:42
@JeanMeche JeanMeche closed this Sep 28, 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 Oct 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

adev: preview 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

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo