Skip to content

Commit ae63110

Browse files
authored
Fix time slicing fixture (facebook#13305)
* Fix time slicing fixture * Remove unused option
1 parent e341e50 commit ae63110

File tree

1 file changed

+17
-17
lines changed
  • fixtures/unstable-async/time-slicing/src

1 file changed

+17
-17
lines changed

fixtures/unstable-async/time-slicing/src/index.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {Component, PureComponent, unstable_AsyncMode} from 'react';
1+
import React, {PureComponent, unstable_AsyncMode} from 'react';
22
import {flushSync, render, unstable_deferredUpdates} from 'react-dom';
33
import _ from 'lodash';
44
import Charts from './Charts';
@@ -64,9 +64,12 @@ class App extends PureComponent {
6464
}
6565
this._ignoreClick = true;
6666

67-
unstable_deferredUpdates(() => {
68-
this.setState({showDemo: true}, () => {
69-
this._ignoreClick = false;
67+
// TODO: needing setTimeout here seems like a React bug.
68+
setTimeout(() => {
69+
unstable_deferredUpdates(() => {
70+
this.setState({showDemo: true}, () => {
71+
this._ignoreClick = false;
72+
});
7073
});
7174
});
7275
};
@@ -79,15 +82,13 @@ class App extends PureComponent {
7982
}
8083
}, 1000);
8184

82-
renderOption(strategy, label, enabled) {
85+
renderOption(strategy, label) {
8386
const {strategy: currentStrategy} = this.state;
8487
return (
8588
<label
86-
className={strategy === currentStrategy ? 'selected' : null}
87-
style={{opacity: enabled ? 1 : 0.5}}>
89+
className={strategy === currentStrategy ? 'selected' : null}>
8890
<input
8991
type="radio"
90-
disabled={!enabled}
9192
checked={strategy === currentStrategy}
9293
onChange={() => this.setState({strategy})}
9394
/>
@@ -107,8 +108,11 @@ class App extends PureComponent {
107108
this.debouncedHandleChange(value);
108109
break;
109110
case 'async':
110-
unstable_deferredUpdates(() => {
111-
this.setState({value});
111+
// TODO: needing setTimeout here seems like a React bug.
112+
setTimeout(() => {
113+
unstable_deferredUpdates(() => {
114+
this.setState({value});
115+
});
112116
});
113117
break;
114118
default:
@@ -124,13 +128,9 @@ class App extends PureComponent {
124128
return (
125129
<div className="container">
126130
<div className="rendering">
127-
{this.renderOption('sync', 'Synchronous', true)}
128-
{this.renderOption('debounced', 'Debounced', true)}
129-
{this.renderOption(
130-
'async',
131-
'Asynchronous',
132-
false
133-
) /* TODO Fix async demo and re-enable */}
131+
{this.renderOption('sync', 'Synchronous')}
132+
{this.renderOption('debounced', 'Debounced')}
133+
{this.renderOption('async', 'Asynchronous')}
134134
</div>
135135
<input
136136
className={'input ' + this.state.strategy}

0 commit comments

Comments
 (0)