data
data copied to clipboard
[3.28->4.7] `isLoaded` does not recompute if checked before the record has loaded.
Reproduction
Please provide one of the following:
This branch has a reproduction, all that is requires is to access a model through realtionship and check isLoaded
before it has Loaded. After the request has finished the record will be stuck in an empty state, this is also because isEmpty also does not recompute.
(https://github.com/Mikek2252/ember-new-output/tree/ember-data-bug)
Description
If isLoaded
is checked on a model that hasn't loaded such as a relationship foo.bar.isLoaded
then you check foo.bar.isLoaded
after the record has loaded it will not recompute isLoaded
and also the state of that record will be set to root.empty
Versions
This occurs on ember-data 3.28 -> 4.7 (it is fixed in 4.8)
This has mainly been added to visibility for anyone else that has this issue, the work around i have been using is to check isFulfilled, but this is not a strict like for like as it requires you to check a promise and doesn't take into account the value being null.
am open to this being fixed for 3.28/4.4 if anyone still using those versions (ahem model-fragments users) wants to contribute a fix.
Im happy to write a fix, but not 100% sure what the best solution would be, in my mind it would be notifying all the related properties instead of just isLoading
here https://github.com/emberjs/data/blob/7a957ddcf20c334fc6eeaf82cfa4f0dbb7795dfc/packages/model/addon/-private/record-state.ts#L210 Would that be fine or is there a better approach?
@Mikek2252 ~~did you check this bug against versions later than 4.7?~~
You suggest this is fixed in 4.8, however, the code in RecordState didn't evolve much between 4.7 and main. I suspect what changed is the isEmpty
notification. Worth investigating that angle, though even on main we should probably notify isEmpty and isLoaded when fulfilled count increases past 0
@runspired So i just had a look at it again and it looks like i made a small mistake, it looks like this was fixed in 4.7
Soo playing around with 4.7 and 4.6 it looks like isLoaded
isn't called until the record is actually loaded in 4.7 where as 4.6 it calls it before. Can't quite work out just yet what is stopping it from running isLoaded
before the call has been completed