@@ -83,6 +83,8 @@ class SpecMap {
8383 // We might consider making this (traversing & application) configurable later.
8484 function createKeyBasedPlugin ( pluginObj ) {
8585 return function * ( patches , specmap ) {
86+ const traversedRefs = { }
87+
8688 for ( const patch of patches . filter ( lib . isAdditiveMutation ) ) {
8789 yield * traverse ( patch . value , patch . path , patch )
8890 }
@@ -102,9 +104,21 @@ class SpecMap {
102104 for ( const key of Object . keys ( obj ) ) {
103105 const val = obj [ key ]
104106 const updatedPath = path . concat ( key )
105-
106- if ( lib . isObject ( val ) ) {
107- yield * traverse ( val , updatedPath , patch )
107+ const isObj = lib . isObject ( val )
108+
109+ // If the object has a meta '$$ref' - and store this $$ref
110+ // in a lookaside to prevent future traversals of this $ref's tree.
111+ const objRef = obj . $$ref
112+ const traversed = specmap . allowMetaPatches && traversedRefs [ obj . $$ref ]
113+
114+ if ( ! traversed ) {
115+ if ( isObj ) {
116+ // Only store the ref if it exists
117+ if ( specmap . allowMetaPatches && objRef ) {
118+ traversedRefs [ objRef ] = true
119+ }
120+ yield * traverse ( val , updatedPath , patch )
121+ }
108122 }
109123
110124 if ( ! isRootProperties && key === pluginObj . key ) {
0 commit comments