Document how React treats different attributes
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 11.8k
- フォーク
- 7.9k
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
facebook/react/issues/9220 の元のディスカッションと、そこで参照されている ReactDOMServerIntegration-test.js および ReactDOMComponent-test.js のケースから始めてください。文書化されている動作を例とテストと比較し、その後 React のドキュメントを更新して、属性値の処理が明確に規定され、列挙されたケースに一貫したガイダンスが示されるようにしてください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, react
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100