-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix component cache for polymorphic field re-renders #2189
Conversation
5acf4bb
to
5e6b566
Compare
Is the template not rerendering when clicking the button still an issue? I tried on latest main and didn't have any issues. |
wdym. Where did u see that there was a re-render of the field? Particularly, when ur |
Sorry ok I was able to reproduce the issue. Previously didn't see it because I was switching between formats on code mode preview. Confirm that this PR resolves it. |
74384e1
to
332df0d
Compare
I think this is ready for review The continuation of this PR. I have removed the fields proxy cache and moved the cache into the linksToManyComponent. containsMany and linksToMany examples should still have the stability they have had previously. |
Its great that the change in cache introduced inside getBoxComponent (that makes cardOrField as a dependency) here fixes the re-ordering template issue seen here #2241. Essentially, it invalidates the componentCache of the box component but that also means any component state is destroyed (without auto-save). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We think this is a reasonable step forward without taking on a big refactor.
It's hard to be sure this doesn't change component stability somewhere else, but we haven't been able to find any examples in the tests. So we can move ahead with this and folks should be on the lookout for any component state loss regressions that we can debug.
The point of this PR is to enable polymorphic fields to re-render upon assigning a subclass to a field of baseclass type. Previously, although the JSON is correctly serialised, the templates were not re-rendering
Solution
The main issue is that
getBoxComponent
was serving a stale cache (componentCache
) bcos it did not take into account changes in the card or field class iecardOrField
. So we added a value inside the cache storingcardOrField
which then serves the most up-to-date BoxComponent ifcardOrField
changed.Digression Risk
As part of pairing on Thursday with @ef4, the outer cache atfieldsComponentsFor
(stableComponents
) was already serving a stale cache that was preventing the code from returning the most up-to-date cache in boxComponent. This several layers of caching made it difficult to debug. We initially thought that this outer-cache was not needed.BUT afterwards I found out that the cache was made for the purpose preventing eager re-renders that causedlinksToManyComponent
andcontainsManyComponent
to re-render -- so I kept the cache in place. Here is the relevant PR #860 by @jurgenwerk. I eventually, decided to keep the cache for specific fields ie plural fields likelinksToManyComponent
andcontainsManyComponent
for simplicity.. also to unblock Spec and Playground work.I plan to pair further with @ef4 to find the best solution here.. I think the more general solution wud be to allowgetBoxComponent
to have better handling for plurals.