Calling added
twice in a publication causes confusing behavior on update
#10314
Labels
added
twice in a publication causes confusing behavior on update
#10314
Reproduction: https://github.com/benweissmann/meteor-double-added-issue
If you have a publication that calls
added
twice, future calls toupdate
don't correctly clear fields.In the reproduction linked above, I have this (very contrived) publication:
For both documents, the field
a
is correctly updated 3 seconds after the publication starts. However, for thedefective
document, the fieldb
is not correctly unset.I think the issue is this
break
: https://github.com/meteor/meteor/blob/devel/packages/ddp-server/livedata_server.js#L56 -- when we calladded
multiple times, we end up with two entries in theprecedenceList
. This is fine forchanged
, because we end up just updating the higher-precedence item. However, for clearing fields, it means that we clear only one entry and end up falling back to the previous entry.I'm happy to write a PR to fix this, but I'm not sure what the correct behavior should be. I think that in most cases, the repeated call to
added
is erroneous, so maybe we should error on the second call to make it easy to find the problematic call? But that might be a pretty big breaking change. Alternatively, we could translate repeated calls toadded
into calls tochanged
, or fix theclearField
method ofSessionDocumentView
to remove all the matching instances from theprecedenceList
.The text was updated successfully, but these errors were encountered: