Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 9130859

Browse files
catchingashfacebook-github-bot
authored andcommitted
Handle ReactDOM type errors
Summary: When re-enabling ReactDOM Flow typing, we discovered Flow errors. This commit suppresses the errors. The controller you requested could not be found. The controller you requested could not be found. Reviewed By: flarnie Differential Revision: D9224137 fbshipit-source-id: e5cbc4887d3296ae9a71523da3bb37de5f16ac4d
1 parent 1a5b27a commit 9130859

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/component/base/DraftEditor.react.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
260260
* editor mode, if any has been specified.
261261
*/
262262
_buildHandler(eventName: string): Function {
263-
const flushControlled = ReactDOM.unstable_flushControlled;
263+
const flushControlled: (fn: Function) => void =
264+
// $FlowFixMe flushControlled is an unstable feature, so not Flow typed
265+
ReactDOM.unstable_flushControlled;
264266
// Wrap event handlers in `flushControlled`. In sync mode, this is
265267
// effetively a no-op. In async mode, this ensures all updates scheduled
266268
// inside the handler are flushed before React yields to the browser.

src/component/contents/DraftEditorLeaf.react.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class DraftEditorLeaf extends React.Component<Props> {
103103

104104
if (child.nodeType === Node.TEXT_NODE) {
105105
targetNode = child;
106+
// $FlowFixMe child may also be an Element, not just Node
106107
} else if (child.tagName === 'BR') {
107108
targetNode = node;
108109
} else {

src/component/contents/__tests__/DraftEditorTextNode-test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,19 @@ const initializeAsNonIE = () => {
4444
};
4545

4646
const expectPopulatedSpan = (stub, testString) => {
47-
const node = ReactDOM.findDOMNode(stub);
47+
// $FlowExpectedError node could be null
48+
const node: Element = ReactDOM.findDOMNode(stub);
4849
expect(node.tagName).toBe('SPAN');
4950
expect(node.childNodes.length).toBe(1);
50-
expect(node.firstChild.textContent).toBe(testString);
51+
expect(node.firstChild && node.firstChild.textContent).toBe(testString);
5152
};
5253

5354
test('must initialize correctly with an empty string, non-IE', function() {
5455
initializeAsNonIE();
5556
const stub = renderIntoContainer(
5657
<DraftEditorTextNode>{''}</DraftEditorTextNode>,
5758
);
59+
// $FlowExpectedError we know node is an Element
5860
expect(ReactDOM.findDOMNode(stub).tagName).toBe('BR');
5961
});
6062

@@ -143,11 +145,13 @@ test('must skip updates if text already matches DOM, non-IE', function() {
143145

144146
renderIntoContainer(<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>);
145147

148+
// $FlowExpectedError property render is missing in HTMLDivElement
146149
expect(stub.render.mock.calls.length).toBe(0);
147150

148151
// Sanity check that updating is performed when appropriate.
149152
renderIntoContainer(<DraftEditorTextNode>{TEST_B}</DraftEditorTextNode>);
150153

154+
// $FlowExpectedError property render is missing in HTMLDivElement
151155
expect(stub.render.mock.calls.length).toBe(1);
152156
});
153157

@@ -161,11 +165,13 @@ test('must skip updates if text already matches DOM, IE', function() {
161165

162166
renderIntoContainer(<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>);
163167

168+
// $FlowExpectedError property render is missing in HTMLDivElement
164169
expect(stub.render.mock.calls.length).toBe(0);
165170

166171
// Sanity check that updating is performed when appropriate.
167172
renderIntoContainer(<DraftEditorTextNode>{TEST_B}</DraftEditorTextNode>);
168173

174+
// $FlowExpectedError property render is missing in HTMLDivElement
169175
expect(stub.render.mock.calls.length).toBe(1);
170176
});
171177

@@ -177,6 +183,7 @@ test('must update from non-empty to empty, non-IE', function() {
177183

178184
renderIntoContainer(<DraftEditorTextNode>{''}</DraftEditorTextNode>);
179185

186+
// $FlowExpectedError we know node is an Element
180187
expect(ReactDOM.findDOMNode(stub).tagName).toBe('BR');
181188
});
182189

@@ -206,9 +213,11 @@ test('must force unchanged text back into the DOM', function() {
206213
<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>,
207214
);
208215

216+
// $FlowExpectedError we know node is not null
209217
ReactDOM.findDOMNode(stub).textContent = TEST_B;
210218

211219
renderIntoContainer(<DraftEditorTextNode>{TEST_A}</DraftEditorTextNode>);
212220

221+
// $FlowExpectedError we know node is not null
213222
expect(ReactDOM.findDOMNode(stub).textContent).toBe(TEST_A);
214223
});

0 commit comments

Comments
 (0)