Commit 4bce2a0
authored
fix: delayed suspense causes "flicker" (#921)
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->
## This PR
<!-- add the description of the PR here -->
- Add an internal `useOpenFeatureClientStatus()` function to make it
slightly easier to keep track of the state of the current Client, and
know when to suspend or not.
- Replaces the `suspend()` function with a `suspendUntilReady()`
function. The `suspendUntilReady()` function fires immediatly during the
first render or when the component cannot render due to the client
having changed status.
- Put the Client status and the feature flag details inside React
states. This is required to make APIs like `startTransition` work
properly with the library
### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->
Fixes #920
### Notes
<!-- any additional notes for this PR -->
### Follow-up Tasks
- [x] Add more tests. Suspense and Transitions are very tricky. While
these changes don't seem to have broken any existing tests, we should
add new tests to make sure Suspense and Transitions continue to work
properly in the future.
- [ ] ~I think there might still be some reactivity issues with some
parts of the codebase. The client returned by `useOpenFeatureClient()`
didn't seem to update properly when the client changed, which made
`useOpenFeatureClientStatus()` not update properly.~ Out of the scope of
this PR
### How to test
<!-- if applicable, add testing instructions under this section -->
I built the application with `npm build`, then `npm pack`. I used the
modified code on a local project to see if it fixed the issues.
I built projects in CodeSanbox that demonstrate the issues.
For Suspense:
https://codesandbox.io/embed/openfeature-suspense-bug-5j7yll?fontsize=14&hidenavigation=1&theme=dark
For Transitions:
https://codesandbox.io/embed/openfeature-suspense-bug-forked-lqhyf3?fontsize=14&hidenavigation=1&theme=dark
---------
Signed-off-by: Tommy Josépovic <[email protected]>1 parent 86a9230 commit 4bce2a0
File tree
7 files changed
+213
-138
lines changed- packages/react
- src
- common
- evaluation
- provider
- test
7 files changed
+213
-138
lines changedThis file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
246 | 247 | | |
247 | 248 | | |
248 | 249 | | |
249 | | - | |
250 | | - | |
| 250 | + | |
251 | 251 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
263 | 269 | | |
264 | 270 | | |
265 | 271 | | |
266 | | - | |
| 272 | + | |
267 | 273 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
| 274 | + | |
272 | 275 | | |
273 | 276 | | |
274 | 277 | | |
275 | 278 | | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 279 | + | |
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
284 | | - | |
285 | | - | |
| 283 | + | |
| 284 | + | |
286 | 285 | | |
287 | 286 | | |
288 | 287 | | |
289 | 288 | | |
290 | 289 | | |
291 | 290 | | |
292 | | - | |
| 291 | + | |
293 | 292 | | |
294 | 293 | | |
295 | 294 | | |
296 | | - | |
| 295 | + | |
297 | 296 | | |
298 | 297 | | |
299 | 298 | | |
300 | | - | |
| 299 | + | |
301 | 300 | | |
302 | 301 | | |
303 | 302 | | |
| |||
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | 22 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
40 | 27 | | |
41 | | - | |
| 28 | + | |
42 | 29 | | |
0 commit comments