fix(logger-plugin): log async action completion in a separate console group#2423
Draft
arturovt wants to merge 1 commit into
Draft
fix(logger-plugin): log async action completion in a separate console group#2423arturovt wants to merge 1 commit into
arturovt wants to merge 1 commit into
Conversation
… 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.
|
View your CI Pipeline Execution ↗ for commit 5f61313
☁️ Nx Cloud last updated this comment at |
@ngxs/devtools-plugin
@ngxs/form-plugin
@ngxs/hmr-plugin
@ngxs/router-plugin
@ngxs/storage-plugin
@ngxs/store
@ngxs/websocket-plugin
commit: |
BundleMonUnchanged files (6)
No change in files bundle size Unchanged groups (1)
Final result: ✅ View report in BundleMon website ➡️ |
BundleMon (NGXS Plugins)Files updated (1)
Unchanged files (8)
Total files change +238B +1.11% Groups updated (1)
Final result: ❌ View report in BundleMon website ➡️ |
BundleMon (Integration Projects)Files updated (1)
Total files change +242B +0.35% Final result: ✅ View report in BundleMon website ➡️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
ActionLoggernow tracks whether sync work has ended and whether the action already completed synchronously, using two private flags. A newsyncWorkComplete()method logs an intermediate state snapshot and closes the first group.NgxsLoggerPlugin.handle()wraps the result observable withafterSubscribe()— a helper that usesmerge+deferto invokesyncWorkComplete()synchronously at subscription time, after the pipeline is set up but before any async emission resolves.action X @ timetoaction X (started @ time)to make the start-time label unambiguous when it reappears in the async completion group.