Skip to content

adjust NgxCVA to be usable with field directive and new signal-based forms - #679

Open
ptandler wants to merge 5 commits into
ngxtension:mainfrom
etalytics:NgxControlValueAccessor-with-field-654
Open

adjust NgxCVA to be usable with field directive and new signal-based forms#679
ptandler wants to merge 5 commits into
ngxtension:mainfrom
etalytics:NgxControlValueAccessor-with-field-654

Conversation

@ptandler

Copy link
Copy Markdown

Fixes #654 see there for details

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the NgxControlValueAccessor directive by integrating Angular's linkedSignal for its core value and disabled states. This change not only modernizes the directive for better alignment with signal-based forms but also resolves a critical injection context bug (NG0203) that could occur during change detection. The update ensures the directive is more resilient and performs correctly in various scenarios, particularly when used independently of NgControl.

Highlights

  • Enhanced NgxControlValueAccessor: The NgxControlValueAccessor directive now utilizes linkedSignal for its value$ and disabled$ properties, which improves compatibility with Angular's signal-based forms and defers initialization until inputs are set.
  • NG0203 Injection Context Bug Fix: A regression bug (NG0203) related to inject() being called outside the injection context has been resolved. This ensures the directive functions correctly and robustly, especially when used without NgControl.
  • Documentation Update: The documentation link in the README.md file has been updated to reflect the new domain.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an Angular NG0203 injection context bug within the NgxControlValueAccessor by refactoring value$ and disabled$ to use linkedSignal with untracked for initialization, and capturing default values during construction. New regression tests have been added to verify the fix. The review comments suggest improving the clarity of JSDoc comments regarding the use of untracked and removing a trailing whitespace character.

Comment on lines +223 to +227
/**
* We need to use untracked here to avoid that the linkedSignal
* is initialized again.
* @ignore
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The comment here is misleading. untracked does not prevent linkedSignal from being re-initialized; it prevents dependency tracking on signals read within its scope. This clarification is important for future maintainability. Let's update the comment to accurately reflect what untracked does in this context.

	/**
	 * We use `untracked` to prevent `linkedSignal` from creating a dependency
	 * on any signals that might be read here. This ensures the source function
	 * is for initialization only and doesn't re-run unexpectedly.
	 * @ignore
	 */

Comment on lines +242 to +246
/**
* We need to use untracked here to avoid that the linkedSignal
* is initialized again.
* @ignore
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to a previous comment, this explanation for using untracked is misleading. It's important for code clarity and maintainability that comments accurately describe the behavior. Let's update this one as well to correctly state that untracked is used to prevent dependency tracking.

	/**
	 * We use `untracked` to prevent `linkedSignal` from creating a dependency
	 * on any signals that might be read here. This ensures the source function
	 * is for initialization only and doesn't re-run unexpectedly.
	 * @ignore
	 */

* Whether this is disabled. If a control is present, it reflects it's disabled state.
*
* @remarks Internally, this uses a `linkedSignal` to delay the initialization until
* the host component's inputs are set to avoid runtime exceptions. */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

There appears to be a trailing whitespace character (a tab) at the end of this line. It should be removed to maintain code cleanliness.

Suggested change
* the host component's inputs are set to avoid runtime exceptions. */
* the host component's inputs are set to avoid runtime exceptions. */

@eneajaho

Copy link
Copy Markdown
Collaborator

Hi @ptandler
Some time has passed since this one was created. Does this work with latest things in SignalForms?

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.

Using NgxControlValueAccessor with [field] causes ERROR RuntimeError: NG0950: Input "field" is required but no value is available yet

2 participants