Repository: DevExpress/devextreme-vue
Pull request #181 (2018-10-29 14:01:26)

 Fix nested config-components duplication
Cherry pick of #180 


Patch:
diff --git a/src/core/component.ts b/src/core/component.ts
index 98ca629..8b17ea3 100644
--- a/src/core/component.ts
+++ b/src/core/component.ts
@@ -167,12 +167,13 @@ function extractChildren(children: VNode[], config: Configuration): VNode[] {
     if (!children || children.length === 0) { return children; }
 
     const nodes: VNode[] = [];
-    pullConfigurations(children, nodes, config);
+    config.cleanNested();
+    pullConfigComponents(children, nodes, config);
 
     return nodes;
 }
 
-function pullConfigurations(children: VNode[], nodes: VNode[], ownerConfig: Configuration): void {
+function pullConfigComponents(children: VNode[], nodes: VNode[], ownerConfig: Configuration): void {
 
     children.forEach((node) => {
         nodes.push(node);
@@ -195,7 +196,7 @@ function pullConfigurations(children: VNode[], nodes: VNode[], ownerConfig: Conf
             (node.componentOptions as any as IConfigurable).$_config = config;
 
             if (node.componentOptions.children) {
-                pullConfigurations(node.componentOptions.children as VNode[], nodes, config);
+                pullConfigComponents(node.componentOptions.children as VNode[], nodes, config);
             }
         }
     });
diff --git a/src/core/configuration.ts b/src/core/configuration.ts
index d7c4f31..c3e1cde 100644
--- a/src/core/configuration.ts
+++ b/src/core/configuration.ts
@@ -4,12 +4,12 @@ type UpdateFunc = (name: string, value: any) => void;
 
 class Configuration {
 
-    private readonly _nestedConfigurations: Configuration[];
     private readonly _name: string | null;
     private readonly _isCollectionItem: boolean;
     private readonly _collectionItemIndex: number | undefined;
     private readonly _initialValues: Record<string, any>;
     private readonly _updateFunc: UpdateFunc;
+    private _nestedConfigurations: Configuration[];
     private _optionChangedFunc: any;
 
     private _options: string[];
@@ -80,6 +80,10 @@ class Configuration {
         });
     }
 
+    public cleanNested() {
+        this._nestedConfigurations = [];
+    }
+
     public createNested(
         name: string,
         initialValues: Record<string, any>,


Test patch:
diff --git a/src/core/component.test.ts b/src/core/component.test.ts
index 52b73d6..03afe99 100644
--- a/src/core/component.test.ts
+++ b/src/core/component.test.ts
@@ -518,6 +518,31 @@ describe("configuration", () => {
         expect(nestedConfig.nested[2].collectionItemIndex).toBe(2);
     });
 
+    it("doesn't add duplicate nested config on render", (cb) => {
+        const vm = new Vue({
+            template:
+                `<test-component>` +
+                `  <nested :prop1="123" />` +
+                `</test-component>`,
+            components: {
+                TestComponent,
+                Nested
+            }
+        }).$mount();
+        const config = (vm.$children[0] as any as IConfigurable).$_config;
+
+        vm.$forceUpdate();
+
+        Vue.nextTick(() => {
+            try {
+                expect(config.nested).toHaveLength(1);
+            } catch (e) {
+                cb.fail(e);
+            }
+            cb();
+        });
+    });
+
 });
 
 describe("nested options", () => {