Skip to content

Conversation

@arturovt
Copy link
Member

@arturovt arturovt commented Dec 19, 2024

An INFINITE_CHANGE_DETECTION error has been logged to the error service multiple times,
occurring randomly depending on the number of actions dispatched in a row. This happens
because a pending task is added every time an action is dispatched. Removing a pending task
via the public API forces a scheduled tick, ensuring that stability is asynchronous and
delayed until there has been at least an opportunity to run app synchronization.

This change reduces the number of change detection cycles. For example, if 10 synchronous
actions are dispatched in a row, it may previously trigger 10 change detection cycles, as
tasks would be removed 10 times.

We listen to the actions stream, and every time a context with a dispatched status is
generated, we add a pending task only once and keep it until the action is completed.
If multiple actions are dispatched at the same time, we debounce them and use buffer
to collect them into a single list.

@nx-cloud
Copy link

nx-cloud bot commented Dec 19, 2024

View your CI Pipeline Execution ↗ for commit 0cb3dab.

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

☁️ Nx Cloud last updated this comment at 2024-12-22 21:05:53 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 19, 2024

Open in Stackblitz

@ngxs/devtools-plugin

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

@ngxs/hmr-plugin

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

@ngxs/form-plugin

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

@ngxs/router-plugin

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

@ngxs/storage-plugin

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

@ngxs/store

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

@ngxs/websocket-plugin

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

commit: 0cb3dab

@bundlemon
Copy link

bundlemon bot commented Dec 19, 2024

BundleMon

Files updated (1)
Status Path Size Limits
fesm2022/ngxs-store.mjs
104.52KB (+1.69KB +1.64%) 105KB / +0.5%
Unchanged files (5)
Status Path Size Limits
fesm2022/ngxs-store-internals.mjs
11.51KB 13KB / +0.5%
fesm2022/ngxs-store-internals-testing.mjs
6.8KB 7KB / +0.5%
fesm2022/ngxs-store-operators.mjs
6.22KB 7KB / +0.5%
fesm2022/ngxs-store-plugins.mjs
2.38KB 3KB / +0.5%
fesm2022/ngxs-store-experimental.mjs
574B 2KB / +0.5%

Total files change +1.69KB +1.29%

Groups updated (1)
Status Path Size Limits
@ngxs/store(fesm2022)[gzip]
./fesm2022/*.mjs
31.86KB (+582B +1.82%) +1%

Final result: ❌

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Dec 19, 2024

BundleMon (NGXS Plugins)

Unchanged files (9)
Status Path Size Limits
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin.m
js
4.03KB +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin.mjs
3.01KB +0.5%
Plugins(fesm2022)[gzip]
hmr-plugin/fesm2022/ngxs-hmr-plugin.mjs
2.61KB +0.5%
Plugins(fesm2022)[gzip]
websocket-plugin/fesm2022/ngxs-websocket-plug
in.mjs
2.57KB +0.5%
Plugins(fesm2022)[gzip]
form-plugin/fesm2022/ngxs-form-plugin.mjs
2.46KB +0.5%
Plugins(fesm2022)[gzip]
devtools-plugin/fesm2022/ngxs-devtools-plugin
.mjs
2.14KB +0.5%
Plugins(fesm2022)[gzip]
logger-plugin/fesm2022/ngxs-logger-plugin.mjs
2.01KB +0.5%
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin-i
nternals.mjs
861B +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin-int
ernals.mjs
396B +0.5%

No change in files bundle size

Unchanged groups (1)
Status Path Size Limits
All Plugins(fesm2022)[gzip]
./-plugin/fesm2022/.mjs
20.05KB +0.5%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Dec 19, 2024

BundleMon (Integration Projects)

Files added (1)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng19/dist-integration/browser/mai
n-(hash).js
+66.38KB +1%
Files removed (3)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng18/dist-integration/browser/mai
n-(hash).js
-70.1KB +1%
Main bundles(Gzip)
hello-world-ng17/dist-integration/main.(hash)
.js
-68.24KB +1%
Main bundles(Gzip)
hello-world-ng16/dist-integration/main.(hash)
.js
-67.3KB +1%

Total files change -139.27KB -67.72%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Copy link
Member

@markwhitfeld markwhitfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the logic change?...
As far as I can see, it was previously creating a task for every action dispatched, but now it creates one and keeps track of the actions dispatched while that pending task is active.
It keeps that pending task active until the last dispatched action completes (the tracked actions go down to zero).

@arturovt
Copy link
Member Author

What is the logic change?... As far as I can see, it was previously creating a task for every action dispatched, but now it creates one and keeps track of the actions dispatched while that pending task is active. It keeps that pending task active until the last dispatched action completes (the tracked actions go down to zero).

I left comments in the code describing the change but haven’t added the commit message yet.

@arturovt arturovt force-pushed the fix/pending-tasks branch 4 times, most recently from 12e517f to 477e98e Compare December 20, 2024 11:06
@arturovt arturovt marked this pull request as ready for review December 20, 2024 13:25
An `INFINITE_CHANGE_DETECTION` error has been logged to the error service multiple times,
occurring randomly depending on the number of actions dispatched in a row. This happens
because a pending task is added every time an action is dispatched. Removing a pending task
via the public API forces a scheduled tick, ensuring that stability is asynchronous and
delayed until there has been at least an opportunity to run app synchronization.

This change reduces the number of change detection cycles. For example, if 10 synchronous
actions are dispatched in a row, it may previously trigger 10 change detection cycles, as
tasks would be removed 10 times.

We listen to the actions stream, and every time a context with a `dispatched` status is
generated, we add a pending task only once and keep it until the action is completed.
If multiple actions are dispatched at the same time, we debounce them and use `buffer`
to collect them into a single list.
@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 0cb3dab and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 95.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 95.3% (0.0% change).

View more on Code Climate.

@arturovt arturovt merged commit 12393de into master Dec 22, 2024
16 checks passed
@arturovt arturovt deleted the fix/pending-tasks branch December 22, 2024 21:27
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.

3 participants