Skip to content

Alternative Event Tracking: withTrackedReducer#266

Merged
rainerhahnekamp merged 11 commits into
mainfrom
pr/wolfmanfx/233
Jan 14, 2026
Merged

Alternative Event Tracking: withTrackedReducer#266
rainerhahnekamp merged 11 commits into
mainfrom
pr/wolfmanfx/233

Conversation

@rainerhahnekamp
Copy link
Copy Markdown
Collaborator

Summary

This PR introduces withTrackedReducer as an alternative approach to tracking reducer-based state changes in Redux DevTools. It addresses limitations in the original withEventsTracking implementation.

The original implementation (based on #231) attempted to automatically track reducer-based state changes via the glitch tracker. However, this approach has fundamental limitations that cannot be resolved with the specified approach.

Several edge cases are documented in the skipped tests within with-events-tracking.spec.ts.

This PR introduces an alternative way, where end users have to use the wrapperd function withTrackedReducer which calls internally updateState using the event's name.

If we proceed with this approach, the following items need to be completed:

  • Update documentation to explain withTrackedReducer usage and when to use it vs withReducer
  • Update demo applications to showcase the new API
  • Remove or deprecate code from the initial withEventsTracking approach (if applicable)
  • Add validation/runtime checks to ensure withTrackedReducer is only used with stores that have devtools and glitch tracking enabled

Comment thread apps/demo/src/app/events-sample/events-sample.component.ts
@michael-small
Copy link
Copy Markdown
Collaborator

I did a preliminary review for now and will give a more formal one in the evening. Looks good though.

One piece missing at the moment: some sort of documentation reference

Comment thread apps/demo/src/app/events-sample/events-sample.component.ts Outdated
Co-authored-by: Michael Small <33669563+michael-small@users.noreply.github.com>
@rainerhahnekamp
Copy link
Copy Markdown
Collaborator Author

@michael-small @wolfmanfx

I see it as temporarily. In the end, we need support for meta-reducers in the core...

@michael-small
Copy link
Copy Markdown
Collaborator

I see it as temporarily. In the end, we need support for meta-reducers in the core...

In that respect, I think this code/approach as-is minus the outstanding items seems legit. But with those outstanding items, I defer to @wolfmanfx on the outstanding considerations. I imagine there will be some more reviewing opportunity then.

Comment thread libs/ngrx-toolkit/src/lib/devtools/with-tracked-reducer.ts
Comment thread libs/ngrx-toolkit/src/lib/devtools/with-tracked-reducer.ts
Comment thread libs/ngrx-toolkit/src/lib/devtools/with-tracked-reducer.ts Outdated
Removed withEventsTracking.
Use withTrackedReducer instead for automatic DevTools action naming from events.

- Remove withEventsTracking feature and its test file
- Export withTrackedReducer as the replacement
- Remove unused onInit/DevtoolsHookContext from devtools types
- Remove devtoolsEventsTracker and eventsTracking option
- Update demo app to use withTrackedReducer
@wolfmanfx
Copy link
Copy Markdown
Collaborator

@rainerhahnekamp I have updated / cleaned the branch. I also vote for the temp solution with the "withTrackedReducer".

@michael-small michael-small linked an issue Jan 4, 2026 that may be closed by this pull request
@michael-small
Copy link
Copy Markdown
Collaborator

Should documentation be rolled into this PR or done in a separate PR?

@rainerhahnekamp
Copy link
Copy Markdown
Collaborator Author

Should documentation be rolled into this PR or done in a separate PR?

@michael-small I'd say separate PR, do you want to do it?

@michael-small
Copy link
Copy Markdown
Collaborator

Should documentation be rolled into this PR or done in a separate PR?

@michael-small I'd say separate PR, do you want to do it?

Yeah

@rainerhahnekamp
Copy link
Copy Markdown
Collaborator Author

Here's the thing. We do have a type check which verifies that withTrackedReducer is used inside a SignalStore with withDevtools and enabled glitched tracking.

The problem is that no one can decipher the error message.

I am playing with the thought of the type error against a runtime error, where end users get a readable error message and understand what they have to do.

What are your thoughts @michael-small and @wolfmanfx

image

@michael-small
Copy link
Copy Markdown
Collaborator

Runtime error seems inline with approached we have used before and seems way less complex.

@rainerhahnekamp
Copy link
Copy Markdown
Collaborator Author

This is ready. We can even backport it to v20.

@rainerhahnekamp rainerhahnekamp merged commit 05a5ad5 into main Jan 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PSA: v21 plan - 20.6.0 works with NgRx v21, Toolkit v21 is live!

4 participants