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 #3081: maintain p-filled properly #3082

Merged
merged 7 commits into from
Aug 2, 2022

Conversation

kalinkrustev
Copy link
Contributor

@kalinkrustev kalinkrustev commented Jul 20, 2022

Fix #3081

@melloware melloware added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Jul 20, 2022
@melloware
Copy link
Member

melloware commented Jul 21, 2022

Instead of

    const currentValue = elementRef.current && elementRef.current.value;
    const isFilled = React.useMemo(() => (
        ObjectUtils.isNotEmpty(props.value) || ObjectUtils.isNotEmpty(props.defaultValue) || ObjectUtils.isNotEmpty(currentValue)
    ), [props.value, props.defaultValue, currentValue]);

Would it be better to lazy evaluate the current rather than store it in a const?

    const isFilled = React.useMemo(() => (
        ObjectUtils.isNotEmpty(props.value) || 
        ObjectUtils.isNotEmpty(props.defaultValue) || 
        (elementRef.current && ObjectUtils.isNotEmpty(elementRef.current.value))
    ), [props.value, props.defaultValue, elementRef.current]);

@kalinkrustev
Copy link
Contributor Author

The problem is that elementRef.current.value must be in the dependencies, otherwise it might change (without a change to elementRef.current) without triggering reevaluation of the memoized value.

@melloware
Copy link
Member

Ahh yes.

@melloware melloware removed the Status: Pending Review Issue or pull request is being reviewed by Core Team label Aug 2, 2022
@melloware melloware merged commit 5e60927 into primefaces:master Aug 2, 2022
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.

Mention, InputText, InputTextArea and Password do not maintain p-filled properly
3 participants