You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem
After upgrading to 0.18, one of my components broke in a subtle way: It contains an input that's supposed to autofocus unless the user explicitly unfocuses it. The input element has a NodeRef attached, allowing me to call .focus() on the element. Preceding the input is a variable amount of other elements.
This worked fine in yew 0.17, however in 0.18 (and also on master), it no longer does: If the amount of elements preceding the input changes, the NodeRef gets invalidated.
Based on trying random stuff™, I've arrived at the conclusion that this is what happens:
After the view() method returns the input at a different position, its Node is assigned to the NodeRef.
Next, the old Node gets dropped, but it still has a reference to the NodeRef, so it resets the NodeRef to the empty state.
Leading to: In the rendered() method, you don't have access to the Node anymore.
Steps To Reproduce
Steps to reproduce the behavior: I have written a project demonstrating the issue (based on current master, runnable with trunk serve): https://github.com/Follpvosten/yew-noderef-problem
Check the console output to see how the NodeRef changes after the first event, and then never changes again with subsequent events.
It also includes instructions in comments on how to apply a workaround and how to verify that it doesn't happen when the amount of elements doesn't change. It demonstrates the problem using my usecase: Attempting to force focus on an input.
In words: Basically, create a component with a variable amount of elements before an element that has a NodeRef attached. The NodeRef will break when the amount of elements changes.
Expected behavior
I'd expect the NodeRef to not be reset and be usable in rendered() in this case.
Environment:
Yew version: v0.18 and up, including master
Rust version: 1.56.1
The text was updated successfully, but these errors were encountered:
Minor update: I've added a function-component branch to my repo now which demonstrates the issue using function components. On the plus side, the experience of moving to the function component API was pretty nice.
Problem
After upgrading to 0.18, one of my components broke in a subtle way: It contains an input that's supposed to autofocus unless the user explicitly unfocuses it. The input element has a NodeRef attached, allowing me to call
.focus()
on the element. Preceding the input is a variable amount of other elements.This worked fine in yew 0.17, however in 0.18 (and also on master), it no longer does: If the amount of elements preceding the input changes, the NodeRef gets invalidated.
Based on trying random stuff™, I've arrived at the conclusion that this is what happens:
view()
method returns the input at a different position, its Node is assigned to the NodeRef.rendered()
method, you don't have access to the Node anymore.Steps To Reproduce
Steps to reproduce the behavior: I have written a project demonstrating the issue (based on current master, runnable with
trunk serve
): https://github.com/Follpvosten/yew-noderef-problemCheck the console output to see how the NodeRef changes after the first event, and then never changes again with subsequent events.
It also includes instructions in comments on how to apply a workaround and how to verify that it doesn't happen when the amount of elements doesn't change. It demonstrates the problem using my usecase: Attempting to force focus on an input.
In words: Basically, create a component with a variable amount of elements before an element that has a NodeRef attached. The NodeRef will break when the amount of elements changes.
Expected behavior
I'd expect the NodeRef to not be reset and be usable in
rendered()
in this case.Environment:
The text was updated successfully, but these errors were encountered: