force-di icon indicating copy to clipboard operation
force-di copied to clipboard

Error when binding value is modified in parent components init handler

Open sankaran1984 opened this issue 2 years ago • 2 comments

Describe the bug I am seeing an error when the binding value is modified in the parent component's init handler.

To Reproduce

  1. create a test lightning App

Testapp.app

<aura:application extends="force:slds">
	<aura:attribute name="buttonLabel" type="String" default="Neutral"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.initHandler}"/>    

    <!-- create following button component using Force-DI -->
    <!-- <lightning:button label="Neutral"></lightning:button> -->   
    <c:di_injector bindingName="lc_button">
        <c:di_injectorAttribute name="label" value="{!v.buttonLabel}"/>
    </c:di_injector>
</aura:application>

TestappController.js

({
	initHandler : function(cmp, evt, helper) {
		cmp.set('v.buttonLabel', 'brand');
	}
})
  1. create custom metadata di_Binding.lc_button
<?xml version="1.0" encoding="UTF-8"?>
<CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <label>lc_button Binding</label>
    <protected>false</protected>
    <values>
        <field>BindingObjectAlternate__c</field>
        <value xsi:nil="true"/>
    </values>
    <values>
        <field>BindingObject__c</field>
        <value xsi:nil="true"/>
    </values>
    <values>
        <field>BindingSequence__c</field>
        <value xsi:nil="true"/>
    </values>
    <values>
        <field>To__c</field>
        <value xsi:type="xsd:string">lightning:button</value>
    </values>
    <values>
        <field>Type__c</field>
        <value xsi:type="xsd:string">LightningComponent</value>
    </values>
</CustomMetadata>

Steps to reproduce the behavior:

  1. Create a scratch org & deploy force-di package
  2. create lightning app & custom metadata as mentioned
  3. preview the app - /c/Testapp.app

Expected behavior No error expected.

Screenshots and text of error observed image

Version Did you try to reproduce the problem against the latest force-di code? yes

sankaran1984 avatar Mar 07 '22 13:03 sankaran1984

@sankaran1984, thanks for reporting this. While I appreciate the narrative above, it would be helpful if you can prepare a sample project with all source code you are describing above that we can reference. My concern is that in attempting to reproduce this, we may inadvertently create something different and go down a wrong path. Thanks for the help.

ImJohnMDaniel avatar Mar 08 '22 15:03 ImJohnMDaniel

Thanks @ImJohnMDaniel Here's my local project in my own dev org where I reproduced this issue,

https://github.com/sankaran1984/MyOrg/tree/main/force-di-issue-83

let me know if you need more information.

Resolution It may not be the best solution, but I manage to fix it in our local repo until this gets properly fixed. Here's my quick fix, line 105 & 112

image

sankaran1984 avatar Mar 08 '22 16:03 sankaran1984