Repository navigation
Commit b3e9dd2
committed
fix(query-persist-client-core/createPersister): await 'storage.setItem' when persisting a query
`persistQuery` in packages/query-persist-client-core/src/createPersister.ts
awaited `serialize` but not `storage.setItem`, so the promise it returns
resolved as soon as the write was started rather than when it finished.
Two consequences with an asynchronous storage such as React Native
AsyncStorage or idb-keyval. `await persister.persistQueryByKey(queryKey,
queryClient)`, which the createPersister docs show being used in `onMutate`
to persist an optimistic update, returned before the entry was in storage.
And a failing write, for example a quota error, surfaced as an unhandled
promise rejection instead of rejecting the returned promise.
`createAsyncStoragePersister` already awaits its `storage.setItem` call in
packages/query-async-storage-persister/src/index.ts.
Adding the `await` fixes both. The two new tests in
packages/query-persist-client-core/src/__tests__/createPersister.test.ts
cover the ordering and the rejection, and both fail without the change.1 parent 1893a96 commit b3e9dd2
3 files changed
Lines changed: 64 additions & 1 deletion
File tree
- .changeset
- packages/query-persist-client-core/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
524 | 582 | | |
525 | 583 | | |
526 | 584 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
0 commit comments