Skip to content

fix(logger-plugin): log async action completion in a separate console group#2423

Draft
arturovt wants to merge 1 commit into
masterfrom
fix/logger-plugin-async-groups
Draft

fix(logger-plugin): log async action completion in a separate console group#2423
arturovt wants to merge 1 commit into
masterfrom
fix/logger-plugin-async-groups

Conversation

@arturovt

Copy link
Copy Markdown
Member

Previously, the logger opened a console group when an action was dispatched and closed it only when the action completed. For async actions this meant the group stayed open while asynchronous work was pending, causing groups for concurrently-dispatched actions to nest inside one another rather than appear sequentially. The result was misleading — actions looked like they hadn't been dispatched at all until the user expanded multiple nested groups.

The fix closes the initial group as soon as all synchronous work is done. If the action then completes asynchronously, a second group is opened at that point with a clearly labelled header: "(async work completed) action X (started @ HH:MM:SS.mmm)" or "(async work error) action X (started @ HH:MM:SS.mmm)". The start timestamp in the header ties the async result back to the original dispatch without requiring nesting.

Implementation details:

  • ActionLogger now tracks whether sync work has ended and whether the action already completed synchronously, using two private flags. A new syncWorkComplete() method logs an intermediate state snapshot and closes the first group.
  • NgxsLoggerPlugin.handle() wraps the result observable with afterSubscribe() — a helper that uses merge + defer to invoke syncWorkComplete() synchronously at subscription time, after the pipeline is set up but before any async emission resolves.
  • The console group header format changes from action X @ time to action X (started @ time) to make the start-time label unambiguous when it reappears in the async completion group.
  • Tests: two new cases cover async success and async error, each interleaving a foreign log call between dispatch and await to demonstrate the flat, non-nested output.

… group

Previously, the logger opened a console group when an action was
dispatched and closed it only when the action completed. For async
actions this meant the group stayed open while asynchronous work was
pending, causing groups for concurrently-dispatched actions to nest
inside one another rather than appear sequentially. The result was
misleading — actions looked like they hadn't been dispatched at all
until the user expanded multiple nested groups.

The fix closes the initial group as soon as all synchronous work is
done. If the action then completes asynchronously, a second group is
opened at that point with a clearly labelled header:
"(async work completed) action X (started @ HH:MM:SS.mmm)"
or "(async work error) action X (started @ HH:MM:SS.mmm)".
The start timestamp in the header ties the async result back to the
original dispatch without requiring nesting.

Implementation details:
- `ActionLogger` now tracks whether sync work has ended and whether
  the action already completed synchronously, using two private flags.
  A new `syncWorkComplete()` method logs an intermediate state snapshot
  and closes the first group.
- `NgxsLoggerPlugin.handle()` wraps the result observable with
  `afterSubscribe()` — a helper that uses `merge` + `defer` to invoke
  `syncWorkComplete()` synchronously at subscription time, after the
  pipeline is set up but before any async emission resolves.
- The console group header format changes from `action X @ time` to
  `action X (started @ time)` to make the start-time label unambiguous
  when it reappears in the async completion group.
- Tests: two new cases cover async success and async error, each
  interleaving a foreign log call between dispatch and await to
  demonstrate the flat, non-nested output.
@nx-cloud

nx-cloud Bot commented Mar 31, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 5f61313

Command Status Duration Result
nx run-many --target=test --all --configuration... ✅ Succeeded 23s View ↗
nx run-many --target=lint --all --exclude=creat... ✅ Succeeded 2s View ↗
nx lint-types store ✅ Succeeded <1s View ↗
nx run-many --target=build --all ✅ Succeeded 39s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-31 17:24:21 UTC

@pkg-pr-new

pkg-pr-new Bot commented Mar 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

@ngxs/devtools-plugin

npm i https://pkg.pr.new/@ngxs/devtools-plugin@2423

@ngxs/form-plugin

npm i https://pkg.pr.new/@ngxs/form-plugin@2423

@ngxs/hmr-plugin

npm i https://pkg.pr.new/@ngxs/hmr-plugin@2423

@ngxs/router-plugin

npm i https://pkg.pr.new/@ngxs/router-plugin@2423

@ngxs/storage-plugin

npm i https://pkg.pr.new/@ngxs/storage-plugin@2423

@ngxs/store

npm i https://pkg.pr.new/@ngxs/store@2423

@ngxs/websocket-plugin

npm i https://pkg.pr.new/@ngxs/websocket-plugin@2423

commit: 5f61313

@bundlemon

bundlemon Bot commented Mar 31, 2026

Copy link
Copy Markdown

BundleMon

Unchanged files (6)
Status Path Size Limits
fesm2022/ngxs-store.mjs
111.92KB 114KB / +0.5%
fesm2022/ngxs-store-operators.mjs
15.53KB 16KB / +0.5%
fesm2022/ngxs-store-internals.mjs
13.74KB 15KB / +0.5%
fesm2022/ngxs-store-internals-testing.mjs
10.32KB 13KB / +0.5%
fesm2022/ngxs-store-plugins.mjs
2.37KB 3KB / +0.5%
fesm2022/ngxs-store-experimental.mjs
574B 2KB / +0.5%

No change in files bundle size

Unchanged groups (1)
Status Path Size Limits
@ngxs/store(fesm2022)[gzip]
./fesm2022/*.mjs
38.3KB +1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon

bundlemon Bot commented Mar 31, 2026

Copy link
Copy Markdown

BundleMon (NGXS Plugins)

Files updated (1)
Status Path Size Limits
Plugins(fesm2022)[gzip]
logger-plugin/fesm2022/ngxs-logger-plugin.mjs
2.26KB (+238B +11.46%) +0.5%
Unchanged files (8)
Status Path Size Limits
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin.m
js
4.12KB +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin.mjs
3.4KB +0.5%
Plugins(fesm2022)[gzip]
hmr-plugin/fesm2022/ngxs-hmr-plugin.mjs
2.72KB +0.5%
Plugins(fesm2022)[gzip]
websocket-plugin/fesm2022/ngxs-websocket-plug
in.mjs
2.58KB +0.5%
Plugins(fesm2022)[gzip]
form-plugin/fesm2022/ngxs-form-plugin.mjs
2.47KB +0.5%
Plugins(fesm2022)[gzip]
devtools-plugin/fesm2022/ngxs-devtools-plugin
.mjs
2.23KB +0.5%
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin-i
nternals.mjs
947B +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin-int
ernals.mjs
453B +0.5%

Total files change +238B +1.11%

Groups updated (1)
Status Path Size Limits
All Plugins(fesm2022)[gzip]
./-plugin/fesm2022/.mjs
21.14KB (+238B +1.11%) +0.5%

Final result: ❌

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon

bundlemon Bot commented Mar 31, 2026

Copy link
Copy Markdown

BundleMon (Integration Projects)

Files updated (1)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng21/dist-integration/browser/mai
n-(hash).js
67.56KB (+242B +0.35%) +1%

Total files change +242B +0.35%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

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.

1 participant