fix(swift): store data model updates before notifying subscribers - #2323
Open
andrewkolos wants to merge 3 commits into
Open
fix(swift): store data model updates before notifying subscribers#2323andrewkolos wants to merge 3 commits into
andrewkolos wants to merge 3 commits into
Conversation
DataModel.data was @published, which emits during willSet: subscribers ran before the new value was stored, so resolution code reading back through dataModel.get resolved every FunctionCall-valued property one update behind, while plain path bindings, resolved from the emitted value, stayed fresh. The data model now stores the update and then emits through dataPublisher, so subscribers reading back through the model see the value they were notified about.
The separate storage property duplicated CurrentValueSubject's own value, leaving two copies that had to stay in sync. Reads and the read-modify-write in set() now go through the subject's value under the same lock; the two initializers collapse into one with a defaulted initial value. The ordering guarantee is unchanged and remains pinned by DataModelTests.subscriberReadingBackThroughModelSeesStoredValue.
pinieb
approved these changes
Aug 18, 2026
The parameter stopped being read when resolution moved into DataContext, and with the data model now storing before it notifies, the live reads inside DataContext match the tree the rebuild was handed, so the parameter has no job left. Removing it also stops the two action trigger closures from copying the whole data tree into an argument that nothing read.
andrewkolos
enabled auto-merge (squash)
August 18, 2026 19:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
DataModel.datawas@Published, and@Publishedemits duringwillSet: subscribers run before the new value is stored.SurfaceViewModelrebuilds the tree synchronously inside that emission, so any resolution that read back throughdataModel.getsaw the previous tree. This means that every property whose value is aFunctionCallobject rendered one data update behind, while plain path bindings (resolved from the emitted value, not the model) stayed fresh, so one surface could show two generations of the same data in the same frame.Change
DataModelnow stores the update first and then emits, through a newdataPublisher. Subscribers that read back through the model get the value they were notified about, which makesDataContext'sdataModel.getreads correct without touching them.Tests that fail on the main branch are included.
API change
dataModel.$datais replaced bydataModel.dataPublisher. Migration is one line at each subscription site (two existed in this repo, both updated).objectWillChangestill fires before mutation, so SwiftUI observation ofDataModelis unaffected.datanow take the model's lock; the old@Publishedstored-property read was unsynchronized against locked writes.Pre-launch Checklist
One time:
For this PR:
- [ ] I have updated the relevant CHANGELOG.md file.If you need help, consider asking for advice on the discussion board.