Skip to content

Fix hot reload when using the Watch widget#398

Open
davidmartos96 wants to merge 2 commits intorodydavis:mainfrom
davidmartos96:fix_hot_reload
Open

Fix hot reload when using the Watch widget#398
davidmartos96 wants to merge 2 commits intorodydavis:mainfrom
davidmartos96:fix_hot_reload

Conversation

@davidmartos96
Copy link

Fixes #390

result.recompute(); in the addPostFrameCallback might get called with an invalid widget context on hot reload. I don't think this block is really needed, because didUpdateWidget is already taking into consideration the builder changing to properly update the "cached" widget signal.

I've tried and it seems to be working ok. Alternatively, if we want to keep the callback, we can add if (!mounted) return at the very beginning. This is the first thing I changed, but then I noticed that on hot reloads, the computed widget signal was being recomputed twice (one the callback and the other the didUpdateWidget), that's why I opted to kee the didUpdateWidget recompute only.

Also, I believe the didUpdateWidget needs to be a separate if statement, not if-else. Otherwise, we don't recompute if the dependencies list changes and the builder also changes.

@holland-nguyen
Copy link

I believe this PR is really necessary to prevent duplicate rebuilds.
Could you consider including it in the next release? @rodydavis. thanks you for this great library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants