yewstack / yew

Rust / Wasm framework for creating reliable and efficient web applications

Home Page:https://yew.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Children of text areas do not get rendered

ranile opened this issue · comments

commented

Problem

textarea s are allowed to have children (see MDN example). They are not rendered by Yew.

Steps To Reproduce

html! { <textarea>{"This is the default value"}</textarea> }

See playground

Expected behavior
The text area should have default value

Screenshots
If applicable, add screenshots to help explain your problem.
image

Environment:

  • Yew version: 0.20
  • Rust version: irrelevant (also i forgot when playground was deployed)
  • Target, if relevant: [e.g. wasm32-unknown-emscripten] wasm32-unknown-unknown
  • Build tool, if relevant: [e.g. wasm-pack, trunk] trunk
  • OS, if relevant: [e.g. MacOS] Linux
  • Browser and version, if relevant: [e.g. Chrome v83]

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later

Fix
VTagInner::TextArea case should be handled here:

pub fn children(&self) -> &VList {
match &self.inner {
VTagInner::Other { children, .. } => children,
_ => {
// This is mutable because the VList is not Sync
static mut EMPTY: VList = VList::new();
// SAFETY: The EMPTY value is always read-only
unsafe { &EMPTY }
}
}
}

The fix should really be implemented after/alongside #3289 to avoid merge conflicts

If we allow children for textarea, should each render reconcile the content of textarea to be the text in the virtual dom?
The specification says children defines initial value, but wouldn't users expect this value to be updated as they provide a new VNode for their component?

I feel it might be better to grant defaultvalue a similar exception like value and checked to have it mapped to property instead of attribute for default value. So users wouldn't try to update children of textarea and expect it to be updated.

i.e.: The following should work currently:

<textarea ~defaultValue="This is the default value" />

But maybe the following should also work:

<textarea defaultvalue="This is the default value" />