Skip to content

[Live] Fixing bug where inputs would not re-render if the value changed #250

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

Merged
merged 1 commit into from
Feb 1, 2022

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Jan 28, 2022

Q A
Bug fix? yes
New feature? no
Tickets Fix #144 and Bug E on #102.
License MIT

NOTE to self: I'm considering reversing this PR as it has some side effects where we lose input values on re-render. That can be solved with data-live-ignore, but it may be better to reverse this, and "fix" the original problem by telling the user to add a data-live-update attribute (or something like that) where we opt INTO re-rendering. There is basically a situation where we don't know if the user will want a form element to re-render (and update the value) or not. And so, the user needs to choose. The question is, which way should the "default" be.

For example, if an input rendered initially empty, then you typed
into it, and, on re-render, the value was set BACK to the original,
the input would not update on re-render, and it would be stuck
with the old value.

This was because the old input node and new input node were seen
as identical... and so morphdom didn't bother to update that node.
However, in reality, the value property of the "old" input had
been changed and would no longer match the value "attribute" of the
incoming input. Effectively, the 2 inputs had different values, but
this difference was not caught by the system.

@@ -5,6 +5,8 @@ import { combineSpacedArray } from './string_utils';
import { buildFormData, buildSearchParams } from './http_data_helper';
import { setDeepData, doesDeepPropertyExist, normalizeModelName } from './set_deep_data';
import { haveRenderedValuesChanged } from './have_rendered_values_changed';
import { normalizeAttributesForComparison } from './normalize_attributes_for_comparison';
import { cloneHTMLElement } from "./clone_html_element";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { cloneHTMLElement } from "./clone_html_element";
import { cloneHTMLElement } from './clone_html_element';

for consistency? :)

@norkunas
Copy link
Contributor

norkunas commented Jan 28, 2022

Ran into a case today where I've defined a modal (with managed form) in a LiveComponent and after changing value in form everything was re-rendered and modal was closed, so data-live-ignore should solve this for me? :)

@weaverryan
Copy link
Member Author

Ran into a case today where I've defined a modal (with managed form) in a LiveComponent and after changing value in form everything was re-rendered and modal was closed, so data-live-ignore should solve this for me? :)

Ideally, yes! That's exactly the case that we should test to make sure works :)

@weaverryan weaverryan force-pushed the live-fix-non-updating-value branch from 8ca3f8c to a27fdd3 Compare February 1, 2022 01:40
@weaverryan weaverryan merged commit 0c6423c into symfony:2.x Feb 1, 2022
@norkunas
Copy link
Contributor

norkunas commented Feb 2, 2022

And I think this also fixed the #102 Bug H?

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.

[LiveComponent] How to clear input form fields?
2 participants