@@ -158,5 +158,86 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
158158 } )
159159 expect ( newData . foo [ 0 ] . isActive ) . toBe ( true )
160160 } )
161+
162+ test ( "#659 no reconciliation after read" , ( ) => {
163+ const bar = { }
164+ const foo = { bar}
165+
166+ const next = produce ( foo , draft => {
167+ draft . bar
168+ draft . bar = bar
169+ } )
170+ expect ( next ) . toBe ( foo )
171+ } )
172+
173+ test ( "#659 no reconciliation after read - 2" , ( ) => {
174+ const bar = { }
175+ const foo = { bar}
176+
177+ const next = produce ( foo , draft => {
178+ const subDraft = draft . bar
179+ draft . bar = bar
180+ subDraft . x = 3 // this subDraft is not part of the end result, so ignore
181+ } )
182+
183+ expect ( next ) . toEqual ( foo )
184+ } )
185+
186+ test ( "#659 no reconciliation after read - 3" , ( ) => {
187+ const bar = { }
188+ const foo = { bar}
189+
190+ const next = produce ( foo , draft => {
191+ const subDraft = draft . bar
192+ subDraft . x = 3 // this subDraft is not part of the end result, so ignore
193+ draft . bar = bar
194+ } )
195+ expect ( next ) . toEqual ( foo )
196+ } )
197+
198+ // Disabled: these are optimizations that would be nice if they
199+ // could be detected, but don't change the correctness of the result
200+ test . skip ( "#659 no reconciliation after read - 4" , ( ) => {
201+ const bar = { }
202+ const foo = { bar}
203+
204+ const next = produce ( foo , draft => {
205+ const subDraft = draft . bar
206+ draft . bar = bar
207+ subDraft . x = 3 // this subDraft is not part of the end result, so ignore
208+ } )
209+
210+ expect ( next ) . toBe ( foo )
211+ } )
212+
213+ // Disabled: these are optimizations that would be nice if they
214+ // could be detected, but don't change the correctness of the result
215+ test . skip ( "#659 no reconciliation after read - 5" , ( ) => {
216+ const bar = { }
217+ const foo = { bar}
218+
219+ const next = produce ( foo , draft => {
220+ const subDraft = draft . bar
221+ subDraft . x = 3 // this subDraft is not part of the end result, so ignore
222+ draft . bar = bar
223+ } )
224+ expect ( next ) . toBe ( foo )
225+ } )
226+
227+ test ( "#659 no reconciliation after read - 6" , ( ) => {
228+ const bar = { }
229+ const foo = { bar}
230+
231+ const next = produce ( foo , draft => {
232+ const subDraft = draft . bar
233+ subDraft . x = 3 // this subDraft is not part of the end result, so ignore
234+ draft . bar = bar
235+ draft . bar = subDraft
236+ } )
237+ expect ( next ) . not . toBe ( foo )
238+ expect ( next ) . toEqual ( {
239+ bar : { x : 3 }
240+ } )
241+ } )
161242 } )
162243}
0 commit comments