139
]);
140
});
141
142
- it('passive effects have the same priority as render', () => {
142
+ it('passive effects never have higher than normal priority', async () => {
143
const {useEffect} = React;
144
- function ReadPriority() {
144
+ function ReadPriority({step}) {
145
Scheduler.unstable_yieldValue(
146
- 'Render priority: ' + getCurrentPriorityAsString(),
146
+ `Render priority: ${getCurrentPriorityAsString()}`,
147
);
148
useEffect(() => {
149
Scheduler.unstable_yieldValue(
150
- 'Passive priority: ' + getCurrentPriorityAsString(),
150
+ `Effect priority: ${getCurrentPriorityAsString()}`,
151
);
152
});
153
return null;
154
}
155
- ReactNoop.act(() => {
156
- ReactNoop.render(<ReadPriority />);
157
- expect(Scheduler).toFlushAndYield([
158
- 'Render priority: Normal',
159
- 'Passive priority: Normal',
160
- ]);
155
162
- runWithPriority(UserBlockingPriority, () => {
156
+ // High priority renders spawn effects at normal priority
157
+ await ReactNoop.act(async () => {
158
+ Scheduler.unstable_runWithPriority(ImmediatePriority, () => {
159
+ ReactNoop.render(<ReadPriority />);
160
+ });
161
+ });
162
+ expect(Scheduler).toHaveYielded([
163
+ 'Render priority: Immediate',
164
+ 'Effect priority: Normal',
165
+ ]);
166
+ await ReactNoop.act(async () => {
167
+ Scheduler.unstable_runWithPriority(UserBlockingPriority, () => {
168
ReactNoop.render(<ReadPriority />);
169
});
170
+ });
171
+ expect(Scheduler).toHaveYielded([
172
+ 'Render priority: UserBlocking',
173
+ 'Effect priority: Normal',
174
+ ]);
175
166
- expect(Scheduler).toFlushAndYield([
167
- 'Render priority: UserBlocking',
168
- 'Passive priority: UserBlocking',
169
- ]);
176
+ // Renders lower than normal priority spawn effects at the same priority
177
+ await ReactNoop.act(async () => {
178
+ Scheduler.unstable_runWithPriority(IdlePriority, () => {
179
+ ReactNoop.render(<ReadPriority />);
180
+ });
181
});
182
+ expect(Scheduler).toHaveYielded([
183
+ 'Render priority: Idle',
184
+ 'Effect priority: Idle',
185
+ ]);
186
+ });
187
+
188
+ it('passive effects have correct priority even if they are flushed early', async () => {
189
+ const {useEffect} = React;
190
+ function ReadPriority({step}) {
191
+ Scheduler.unstable_yieldValue(
192
+ `Render priority [step ${step}]: ${getCurrentPriorityAsString()}`,
193
+ );
194
+ useEffect(() => {
195
+ Scheduler.unstable_yieldValue(
196
+ `Effect priority [step ${step}]: ${getCurrentPriorityAsString()}`,
197
+ );
198
+ });
199
+ return null;
200
+ }
201
+ await ReactNoop.act(async () => {
202
+ ReactNoop.render(<ReadPriority step={1} />);
203
+ Scheduler.unstable_flushUntilNextPaint();
204
+ expect(Scheduler).toHaveYielded(['Render priority [step 1]: Normal']);
205
+ Scheduler.unstable_runWithPriority(UserBlockingPriority, () => {
206
+ ReactNoop.render(<ReadPriority step={2} />);
207
+ });
208
+ });
209
+ expect(Scheduler).toHaveYielded([
210
+ 'Effect priority [step 1]: Normal',
211
+ 'Render priority [step 2]: UserBlocking',
212
+ 'Effect priority [step 2]: Normal',
213
+ ]);
214
});
215
216
it('after completing a level of work, infers priority of the next batch based on its expiration time', () => {
256
Scheduler.unstable_flushUntilNextPaint();
257
expect(Scheduler).toHaveYielded(['A', 'B', 'C']);
258
});
216
-
217
- // TODO
218
- it.skip('passive effects have render priority even if they are flushed early', () => {});
259
});