Repository navigation
Commit 6165081
Checked for missed updates in effect create phase
Summary:
There are regressions in the useResourceEffect experiment. We believe this may be due to a behavior difference rather than a problem with useResourceEffect itself. The two branches are meant to have identical behavior but it looks like there is a regression when a component mounts and the store updates before effects run.
In the case of missed updates on mount, the original behavior is:
- update `useEffect` runs
- check for missed updates
- with missed updates, setState and return
- create `useEffect` runs
- `storeSubscriptionRef` was not assigned in update, due to early return for missed updates
- `subscribeToSnapshot` called - *(note: comments in the update effect claim this should not be done until second render when missed updates are synced)*
- `storeSubscriptionRef.current` is set
- new render due to missed updates setState
- update `useEffect` runs
- `storeSubscriptionRef` is set but environment/selector have not changed, so return early
- create `useEffect` runs
- `storeSubscriptionRef` is set, so return early
The useResourceEffect behavior (before this diff) is:
- useResourceEffect create phase runs
- `subscribeToSnapshot` is called and resource is created
- **missed updates are not checked**
- *¿maybe some other update causes a rerender?*
- `useResourceEffect` update phase runs
- if environment/selector have changed, return early and **still don't check for missed updates**
- else, check for missed updates...
The useResourceEffect behavior (with this diff) is:
- `useResourceEffect` create phase runs
- check for missed updates
- with missed updates, setState and setup resource object with `subscribed:false`
- new render due to missed updates setState
- `useResourceEffect` update phase runs
- check for missed updates
- updates should have been synced by now from previous render
- `subscribeToSnapshot` called and subscription object is updated
Iterating on useResourceEffect experiments. We may be dropping missed update syncs here due to not checking for missed updates in the create phase. Moving the check to happen in both create/update.
Reviewed By: poteto, tyao1
Differential Revision: D68562780
fbshipit-source-id: 63e5165cff4b4e931779e2a1b2da7fbebbbdf8881 parent 61c7de9 commit 6165081
1 file changed
Lines changed: 60 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
582 | 583 | | |
583 | 584 | | |
584 | 585 | | |
585 | | - | |
586 | 586 | | |
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
591 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
592 | 626 | | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
593 | 642 | | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
| 643 | + | |
| 644 | + | |
598 | 645 | | |
599 | 646 | | |
600 | 647 | | |
601 | 648 | | |
602 | | - | |
603 | 649 | | |
604 | 650 | | |
605 | 651 | | |
606 | 652 | | |
| 653 | + | |
607 | 654 | | |
608 | 655 | | |
609 | 656 | | |
| |||
616 | 663 | | |
617 | 664 | | |
618 | 665 | | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
642 | 670 | | |
643 | 671 | | |
644 | 672 | | |
645 | 673 | | |
646 | 674 | | |
647 | 675 | | |
| 676 | + | |
648 | 677 | | |
649 | 678 | | |
650 | 679 | | |
| |||
653 | 682 | | |
654 | 683 | | |
655 | 684 | | |
| 685 | + | |
656 | 686 | | |
657 | 687 | | |
658 | 688 | | |
| |||
0 commit comments