Skip to content

Commit f805ffb

Browse files
Copilotchiaramooney
andcommitted
Improve fast refresh simulation to use timer-based approach instead of user interaction
Co-authored-by: chiaramooney <34109996+chiaramooney@users.noreply.github.com>
1 parent 7ec5a64 commit f805ffb

File tree

3 files changed

+530
-510
lines changed

3 files changed

+530
-510
lines changed

packages/@react-native-windows/tester/src/js/examples/View/ViewExample.windows.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,11 @@ function BoxSizingExample(): React.Node {
673673

674674
class FastRefreshStyleExample extends React.Component<
675675
$ReadOnly<{}>,
676-
{currentStyle: number},
676+
{currentStyle: number, isAutoRefreshing: boolean},
677677
> {
678-
state: {currentStyle: number} = {
678+
state: {currentStyle: number, isAutoRefreshing: boolean} = {
679679
currentStyle: 0,
680+
isAutoRefreshing: false,
680681
};
681682

682683
styles = [
@@ -686,13 +687,32 @@ class FastRefreshStyleExample extends React.Component<
686687
{backgroundColor: '#96ceb4', padding: 10, borderRadius: 20},
687688
];
688689

690+
intervalId: ?IntervalID = null;
691+
692+
componentDidMount() {
693+
// Start auto-refresh after a short delay to simulate fast refresh behavior
694+
this.intervalId = setInterval(() => {
695+
if (this.state.isAutoRefreshing) {
696+
this.setState({
697+
currentStyle: (this.state.currentStyle + 1) % this.styles.length,
698+
});
699+
}
700+
}, 2000);
701+
}
702+
703+
componentWillUnmount() {
704+
if (this.intervalId) {
705+
clearInterval(this.intervalId);
706+
}
707+
}
708+
689709
render(): React.Node {
690710
return (
691711
<View testID="view-test-fast-refresh" accessible accessibilityLabel="Fast Refresh Example">
692712
<Pressable onPress={this._handlePress}>
693713
<View style={this.styles[this.state.currentStyle]}>
694714
<RNTesterText style={{color: 'white', fontSize: 14, textAlign: 'center'}}>
695-
Tap to change style (simulates fast refresh)
715+
{this.state.isAutoRefreshing ? 'Auto-refreshing styles...' : 'Tap to start fast refresh simulation'}
696716
</RNTesterText>
697717
<RNTesterText style={{color: 'white', fontSize: 12, textAlign: 'center', marginTop: 5}}>
698718
Style: {this.state.currentStyle + 1} of {this.styles.length}
@@ -705,7 +725,7 @@ class FastRefreshStyleExample extends React.Component<
705725

706726
_handlePress = () => {
707727
this.setState({
708-
currentStyle: (this.state.currentStyle + 1) % this.styles.length,
728+
isAutoRefreshing: !this.state.isAutoRefreshing,
709729
});
710730
};
711731
}

packages/e2e-test-app-fabric/test/ViewComponentTest.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,22 @@ describe('View Tests', () => {
208208
const initialDump = await dumpVisualTree('view-test-fast-refresh');
209209
expect(initialDump).toMatchSnapshot('initial-state');
210210

211-
// Click to change style (simulating fast refresh behavior)
211+
// Click to start auto-refresh (simulating fast refresh activation)
212212
await componentsTab.click();
213213

214-
// Wait a moment for the style change to apply
214+
// Wait for automatic style changes to occur (simulating fast refresh)
215215
await app.waitUntil(
216216
async () => {
217217
const currentDump = await dumpVisualTree('view-test-fast-refresh');
218218
return currentDump !== initialDump;
219219
},
220220
{
221-
timeout: 3000,
222-
timeoutMsg: 'View style did not update after interaction',
221+
timeout: 5000,
222+
timeoutMsg: 'View style did not auto-update during fast refresh simulation',
223223
}
224224
);
225225

226-
// Take snapshot after style change
226+
// Take snapshot after automatic style change
227227
const updatedDump = await dumpVisualTree('view-test-fast-refresh');
228228
expect(updatedDump).toMatchSnapshot('updated-state');
229229
});

0 commit comments

Comments
 (0)