Document how React treats different attributes
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 11
描述
This issue was originally reported by @MMeent via facebook/react/issues/9220
Please refer to the original issue for the related discussion thread.
Text of original issue:
As of #9106 there are quite a lot of tests for HTML's boolean properties on tags. According to these tests HTML properties should get rendered into empty strings or not set, e.g. <div hidden={true} /> should render to <div hidden="" /> and <div hidden={false} /> should render to <div />.
But when I look further, there are other tests which do similar things: <a href={true} /> should render to <a href="true" />. This means that if I take true as my property value, I will not know what the result will be.
The issue being: React currently does not have a clearly-defined and documented way with which they handle their props. Could the docs be updated to specify which type of prop will result in what? e.g. "any number gets parsed to a string (using Number.toString()), an object gets stringified by using arg => Object.entries(arg).map(([key, val]) => ${key}: ${val};).join(), and booleans toggle the property."
In short, these are the bugs/undocumented features/contradictions that the tests expect to happen, plus my expectations:
prop={true}gets parsed toprop=""orprop="true"for select properties
expected: eitherprop=""orprop="prop", not both // as per checked=checked HTML standardprop=""gets parsed asprop=""or
expected:prop=""prop="prop"might get parsed as eitherprop="prop",prop=""or even
expected:prop="prop"prop="foo"=>prop=""orprop="foo"
expected:prop="foo"prop={false}=>orprop="false"
expected:prop={['foo', 'bar']}=>prop=""orprop="foo,bar"(hand-tested, no automatic test available)
expected:prop="foo bar"prop={{foo: 'bar', baz: 5}}=>prop=""orprop="foo: bar; baz: 5;"orprop="[object Object]"(hand-tested, no automatic test available)
expected:prop="foo: bar; baz: 5"// as per style object transform
Hacky showcase: https://jsfiddle.net/ox8a7vfe/3/
Are these features or are these bugs?
If they are bugs, and work is going to be done on the props value parsing, then the following might be a nice addition:
prop={{foo: true, bar: true, baz: false}}=>prop="foo bar"// render alltruekeys, disregardfalsekeys, like classNames.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 facebook/react/issues/9220 的原始討論以及其中引用的 ReactDOMServerIntegration-test.js 和 ReactDOMComponent-test.js 案例開始。將文件中描述的行為與範例和測試進行比較,然後更新 React 文件,以便明確規定屬性值的處理方式,並讓所列案例具有一致的指引。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, react
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100