Skip to content
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

[3.28->4.7] isLoaded does not recompute if checked before the record has loaded. #9232

Open
Mikek2252 opened this issue Feb 22, 2024 · 6 comments

Comments

@Mikek2252
Copy link
Contributor

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)

@Mikek2252
Copy link
Contributor Author

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.

@runspired runspired changed the title isLoaded does not recompute if checked before the record has loaded. [3.28->4.7] isLoaded does not recompute if checked before the record has loaded. Mar 11, 2024
@runspired
Copy link
Contributor

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.

@Mikek2252
Copy link
Contributor Author

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

Would that be fine or is there a better approach?

@runspired
Copy link
Contributor

runspired commented Apr 4, 2024

@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

@Mikek2252
Copy link
Contributor Author

@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

@Mikek2252
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: in progress
Development

No branches or pull requests

2 participants