`NodeRef` documentation is misleading about usage with `use_effect_with`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 70/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- rust
- Domain
- documentation
Research direction
Start with the use_node_ref documentation in packages/yew/src/functional/hooks/use_ref.rs and the manual event listener examples in website/docs/concepts/html/events.mdx. Review how these examples describe passing a NodeRef to use_effect_with, then update the guidance so the documented behavior and limitations are clear and the examples no longer mislead users.
Written by the indexing model from the issue text.
Description
This is about:
- A typo
- Inaccurate/misleading documentation (e.g. technically incorrect advice)
- Undocumented code
- Outdated documentation
- Other
Problem
This is a follow up to #4225. I closed that as a duplicate because I realized that the NodeRef behavior is intentional and other people have brought it up before, but after looking at the documentation more I think I was accidentally misled several times and that's what led to my misunderstanding.
Examples:
The docs for use_node_ref pass the node ref into use_effect_with:
There is even a tip that says:
This is misleading and is the exact example I used in #4225. If you conditionally render an element, its NodeRef::get method will return None until it is rendered the first time. Since NodeRef uses pointer equality for PartialEq, the effect will never run again after that even when NodeRef is eventually Some because the node was rendered.
The specific events example from #4225 and the buggy use_event hook in yew-hooks that I cite in that issue are both essentially just cleaned up versions of the "Manual event listener" examples from the docs.
From "Using Closure (verbose)":
From "Using gloo (concise)":
Both of these also pass a NodeRef into use_effect_with which will only work in certain very simple cases.
Questionaire (Optional)
- I'd like to write this documentation
- I'd like to write this documentation but I'm not sure what's needed
- I don't have time to add this right now, but maybe later
I'm happy to help resolve this and update the docs, but I'd appreciate some guidance for how you'd like me to word the changes. I'm just hoping to fix this so future people (including my future forgetful self) don't make the same mistakes. This is a subtle footgun that is easy to mess up if you're not very careful.
- Dominant language
- Rust
- Stars
- 32.8k
- Forks
- 1.5k
- Avg merge
- 5h 34m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from yewstack/yew
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
documentation
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
documentation
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100