You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[@wordpress/core-data] getEntityRecords and saveEntityRecord don't sync data correctly #22127
Describe the bug
When using getEntityRecords and saveEntityRecord within a single component, I expect that when saveEntityRecord is called, we will not see another fetch of the data (getEntityRecords) until the saveEntityRecord data is finished saving.
What I see instead is that on call of saveEntityRecord the cache is invalidated too soon and getEntityRecords fetches stale data. This causes flickers and the data on screen to be out of date. I have tested this behaviour in withSelect and also useSelect and it behaves the same way in both.
When debugging I found it hard to always get consistent behaviour which makes me think a race condition exists, but quite frequently I do see that core-data's saveEntityRecord triggers 2 RECEIVE_ITEMSactions here, the first of which invalidates the cache conditions for getEntityRecordsdefined here.
I'm not sure if this is a red herring at this stage, but I couldn't find another reason for the immediate fetch behaviour.
Additionally this issue seems similar to others I've seen such as #19132 but this is in the context of core-data so I felt like it should be a unique issue.
To reproduce
I have produced a minimal reproduction in a dummy plugin in a branch here. You should be able to run it as you would normally run gutenberg in development, go to the core data issue plugin and see a list of items, as you check the items they will either flicker back and forth from their checked state or start to get out of sync very quickly.
The code responsible for the fetch/save functionality is here
Expected behavior
The expected behaviour would be that the checkbox would finish saving completely before the new collection is fetched. This would allow the fetched data to be completely up to date.
Screenshots
Editor version (please complete the following information):
WordPress version: 5.5-alpha-47766 (in development mode) but I've seen it in 5.4 as well.
"gutenberg plugin"
Desktop (please complete the following information):
#26627 and #26575 improved the situation here. There is much less flickering, although there is still some of it as seen below:
I think locks would be the ultimate solution here. The downside is that they would add a layer of complexity to an already complex core-data so I'm still trying to come up with some alternatives. But for reference, see the same interaction with #26389 applied:
Activity
chriskmnds commentedon May 8, 2020
This seems related: #19752 Similar issue with flickering when updating.
noisysocks commentedon Oct 13, 2020
It looks like @adamziel ran into this here, so I'm removing Needs Testing: #25859 (comment)
adamziel commentedon Oct 19, 2020
This bites us a lot in the widgets editor, let's take a stab at it as soon as possible cc @noisysocks @draganescu @TimothyBJacobs @youknowriad.
adamziel commentedon Nov 3, 2020
#26627 and #26575 improved the situation here. There is much less flickering, although there is still some of it as seen below:
I think locks would be the ultimate solution here. The downside is that they would add a layer of complexity to an already complex core-data so I'm still trying to come up with some alternatives. But for reference, see the same interaction with #26389 applied:
cc @youknowriad @samueljseay
adamziel commentedon Nov 3, 2020
The flicker on my first gif above is caused by:
bookwithID = 11, no resolution is triggered, we’re good,PUT#1request is waiting for response.bookwithID = 10, no resolution is triggered, we’re good,PUT#2request is waiting for response.PUT#1finishes, invalidates the entity. I have auseSelectcall that callsgetEntityRecords(). AGETrequest is issued and awaits response.GETis finished, it will issueRECEIVE_ITEMSand update the list of entities, including the ones handled byPUT#2.Different things could happen depending on the resolution order too.
adamziel commentedon Nov 10, 2020
Since #26389 is now merged, I'm closing this one. Feel free to comment or reopen if the fix did not fully help!