Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): use computed in selectSignal #2201

Merged
merged 3 commits into from
Aug 6, 2024
Merged

Conversation

arturovt
Copy link
Member

@arturovt arturovt commented Aug 4, 2024

Note: it is necessary to revert these changes and cease experimenting
with decoupling signal changes.

Previously, an issue was reported where calling dispatch from within an
effect caused an error indicating that signal writes are not allowed. We attempted
to resolve this by decoupling state signal changes through debouncing them, ensuring
that consumers always received signal updates asynchronously. However, we should no
longer pursue this approach because it fixes initial issues while introducing new ones.
It is the responsibility of developers to ensure a valid reactive context when updating
signals. The dispatch function can be wrapped in untracked, as it is common practice
to disallow updates to ANY signal within effects, not just NGXS state.

Debouncing signals disrupts zoneless server-side rendering because Angular is unaware
of tasks scheduled by the debounceTime operator. Consequently, content is serialized
before the debounceTime timer fires internally, which updates the signal and allows
the view to reflect the updated value.

Copy link

nx-cloud bot commented Aug 4, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 0a67567. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

Copy link

bundlemon bot commented Aug 4, 2024

BundleMon (Integration Projects)

Files updated (2)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng16/dist-integration/main.(hash)
.js
67.57KB (-1.03KB -1.51%) +1%
Main bundles(Gzip)
hello-world-ng17/dist-integration/main.(hash)
.js
68.55KB (-1.09KB -1.57%) +1%

Total files change -2.13KB -1.54%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@arturovt arturovt force-pushed the fix/revert-to-computed branch 2 times, most recently from f752bf2 to 4b54fda Compare August 4, 2024 17:49
Note: it is necessary to revert these changes and cease experimenting
with decoupling signal changes.

Previously, an issue was reported where calling `dispatch` from within an
effect caused an error indicating that signal writes are not allowed. We attempted
to resolve this by decoupling state signal changes through debouncing them, ensuring
that consumers always received signal updates asynchronously. However, we should no
longer pursue this approach because it fixes initial issues while introducing new ones.
It is the responsibility of developers to ensure a valid reactive context when updating
signals. The `dispatch` function can be wrapped in `untracked`, as it is common practice
to disallow updates to ANY signal within effects, not just NGXS state.

Debouncing signals disrupts zoneless server-side rendering because Angular is unaware
of tasks scheduled by the `debounceTime` operator. Consequently, content is serialized
before the `debounceTime` timer fires internally, which updates the signal and allows
the view to reflect the updated value.
@arturovt arturovt force-pushed the fix/revert-to-computed branch from 4b54fda to 7922a1b Compare August 5, 2024 10:39
@arturovt arturovt marked this pull request as ready for review August 5, 2024 10:40
@arturovt arturovt linked an issue Aug 5, 2024 that may be closed by this pull request
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.

I think there may be a better way to resolve this.
Let's pair on this to come to a good solution.

PS. Why were the tests for packages/store/tests/select-signal-on-provider-levels.spec.ts removed?

@markwhitfeld
Copy link
Member

markwhitfeld commented Aug 5, 2024

I'm wondering if by reverting to this first solution, updates to the state from an effect will not propagate to the components when doing zoneless. I need to check if the use of untracked will prevent the triggering of the change detection from state changes... hopefully it is just about tracking consumers and doesn't affect the triggering of interested consumers.
Could you add a zoneless test in your PR to verify?

PS. I have an idea that may work for all cases. I'll investigate tomorrow morning and then we can discuss.

Copy link

codeclimate bot commented Aug 6, 2024

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

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

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

View more on Code Climate.

@arturovt arturovt merged commit d917fba into master Aug 6, 2024
13 checks passed
@arturovt arturovt deleted the fix/revert-to-computed branch August 6, 2024 15:49
@markwhitfeld markwhitfeld added this to the v18.1.1 milestone Aug 6, 2024
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.

🐞[BUG]: selectSignal cannot be called outside an injection context
3 participants