-
Notifications
You must be signed in to change notification settings - Fork 4
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 shared model manager warning #2044
base: master
Are you sure you want to change the base?
Conversation
afterAttachToDocument is called before the shared model manager is ready. This then causes a warning when a shared model is accessed by a tile using afterAttachToDocument.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2044 +/- ##
==========================================
+ Coverage 79.76% 81.94% +2.17%
==========================================
Files 649 649
Lines 32084 32089 +5
Branches 8401 8405 +4
==========================================
+ Hits 25592 26295 +703
+ Misses 6136 5487 -649
+ Partials 356 307 -49
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Passing run #9181 ↗︎
Details:
Review all test suite changes for PR #2044 ↗︎ |
This code has completely changed in PRs #2028 / #2037 so this will certainly cause conflicts there. However, it answers one of the big questions that I had since taking some actions after shared model manager is ready is still important. So, we can merge this to fix the error on master and then make similar changes in the multi-dataset branch. |
Thanks @bgoldowsky. I think it would be good to see if @kswenson has comments on this, but Boris if it makes your work easier go ahead and merge it and we can address any issues from Kirk in another PR. |
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.
I think this issue has gotten a bit muddled. The reason I added support for afterAttachToDocument()
was to simplify things for clients, notably around the issue of references, as my comment suggests. The tile content's afterAttach()
is called at a time when reference resolution will fail, whereas afterAttachToDocument()
is called at a time when reference resolution can succeed. At the time that I added that code originally it was certainly the case that code that failed (i.e. threw a reference resolution exception) before the change succeeded after I added afterAttachToDocument()
.
Part of the muddle is that it is almost certainly true that the reference in question was to a shared model, but I don't know whether it's necessarily true that all references from tile content to other MST models will be to shared models. 🤷 In any case, I take your main point to be that since the shared model manager isn't guaranteed to be ready in afterAttachToDocument()
that a MobX reaction is required to wait for it in any case, so every tile should have its own MobX reaction and that reaction can be in each tile's afterAttach()
rather than afterAttachToDocument()
.
My inclination would be to go the other way -- why should every tile have to implement the same subtly confusing MobX reaction? Why not put the reaction in TileModel
itself and then call afterAttachToDocument()
when the shared model manager is ready, passing whatever arguments would be useful to the client? In other words, rather than abandoning afterAttachToDocument()
we can make it more useful by delaying it until the shared model manager is ready. It seems to me that would simplify things for clients and mean that the subtly confusing reaction could be written in one place in the TileModel
rather than requiring that every tile have its own version of it.
I'm also confused by this comment in the PR description:
Also note that the tile will always be attached to the document when the shared model manager is ready, so there isn't a need for the
afterAttachToDocument
.
which is clearly not correct and, in fact, belied by the rest of the PR.
I agree that we should try to simplify things for clients (tiles), but I didn't find a simple way to do that since most tiles need to observe different things not just the sharedModelManager and whether it is ready. Regarding the "Also note that..." comment: here is a more precise version of it:
This is because the sharedModelManager is available via the document's environment. So when the tile content model is just attached to the tile but the tile is not attached to the document, there won't be a shared model manager available. |
@bgoldowsky since this conflicts with your other changes, and this PR needs more discussion, don't let it hold up your other work. After your other work is merged in I can fix this up. @kswenson for reference for our conversation, here are the afterAttach dependencies for tiles:
An interesting note is that we are using the "default" built in comparer: https://mobx.js.org/computeds.html#built-in-comparers so the lists of dependencies I provided above are not actually right. In all of these reactions we are re-creating the "value" object, so this new object will be different every time. Therefore any change to a MobX observable accessed in the value function will cause the reaction to run again. |
It is not holding up my work. I have this afterAttach in my branch now. It can potentially be simplified in the future if you make the changes under discussion.
|
These notes documents how tiles are using afterAttach. They also describe a way to unify the updateAfterSharedModelChanges and the way afterAttach is being used.
After discussing this with this with Kirk and doing more brainstorming and evaluation, I'm going to put this PR on hold. It now includes some of my notes in
|
It should be within the document rather than global. |
afterAttachToDocument
is called before the shared model manager is ready.This then causes a warning when a shared model is accessed by a tile using afterAttachToDocument.
The specific warning this prevents is:
shared-model-document-manager.ts:162 getTileSharedModels has no document
This warning was harmless because the reaction in graph tile would just get called a second time when the shared model manager was ready. But it seems better, to just wait until the shared model manager is ready before trying to access the data.
Also note that the tile will always be attached to the document when the shared model manager is ready, so there isn't a need for the
afterAttachToDocument
.