cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hajekj
MVP

Strange behavior of updateView in PCF

Hey there, so I noticed a very strange behavior with PCF local sandbox:

 

It appears that when I call notifyOutputChanged() I end up with updateView(...) being triggered many times (2x for each property added) and with some very weird parameters. I enclosed the sample below. I am running pcf-scripts and pcf-start of 1.3.6 (latest at the moment of writing) and same for pac tool.

 

The output basically is (highlighted the weird parts):

Resource file 'bundle.js' loaded.
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous undefined incoming val
index.ts:46 sampleProperty change value testChanged
index.ts:48 notify
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous testChanged incoming val
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous val incoming testChanged
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous testChanged incoming testChanged
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous testChanged incoming testChanged
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous testChanged incoming testChanged
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous testChanged incoming testChanged
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous testChanged incoming testChanged
index.ts:40 udpateViewTriggered
index.ts:41 sampleProperty previous testChanged incoming testChanged

 

Since this is not happening when the control is deployed to Power Apps, I would consider this a bug. It is quite annoying when debugging stuff locally...

 

 

 

import {IInputs, IOutputs} from "./generated/ManifestTypes";

export class updateViewTest implements ComponentFramework.StandardControl<IInputs, IOutputs> {
	constructor()
	{

	}

	private _rendered: boolean = false;
	private _notify: () => void;
	private sampleProperty: string;

	public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container:HTMLDivElement)
	{
		this._notify = notifyOutputChanged;
	}

	public updateView(context: ComponentFramework.Context<IInputs>): void
	{
		console.log("udpateViewTriggered");
		console.log("sampleProperty", "previous", this.sampleProperty, "incoming", context.parameters.sampleProperty.raw);
		this.sampleProperty = context.parameters.sampleProperty.raw ?? "";
		if(!this._rendered) {
			this._rendered = true;
			console.log("sampleProperty change value", "testChanged");
			this.sampleProperty = "testChanged";
			console.log("notify");
			this._notify();
		}
	}

	public getOutputs(): IOutputs
	{
		return {
			sampleProperty: this.sampleProperty,
			sampleProperty2: "test2",
			sampleProperty3: "test2",
			sampleProperty4: "test2"
		};
	}

	public destroy(): void
	{
	}
}
<?xml version="1.0" encoding="utf-8" ?>
<manifest>
  <control namespace="hajekj" constructor="updateViewTest" version="0.0.1" display-name-key="updateViewTest" description-key="updateViewTest description" control-type="standard">
    <property name="sampleProperty" display-name-key="Property_Display_Key" description-key="Property_Desc_Key" of-type="SingleLine.Text" usage="bound" required="true" />
    <property name="sampleProperty2" display-name-key="Property_Display_Key" description-key="Property_Desc_Key" of-type="SingleLine.Text" usage="bound" required="true" />
    <property name="sampleProperty3" display-name-key="Property_Display_Key" description-key="Property_Desc_Key" of-type="SingleLine.Text" usage="bound" required="true" />
    <property name="sampleProperty4" display-name-key="Property_Display_Key" description-key="Property_Desc_Key" of-type="SingleLine.Text" usage="bound" required="true" />
    <resources>
      <code path="index.ts" order="1"/>
    </resources>
  </control>
</manifest>

 

 

 

8 REPLIES 8
Erlandcrf
Microsoft
Microsoft

Hello,

 

Thanks for bringing this into our attention, looks that what you have described here is definitely odd, I will talk to additional internal resources on this incident and we will dig deeper from our end. We appreciate you bringing this to our visibility and hopefully this will prove useful to other communities users who encounter similar issues.

 

Thanks.

Hi @Erlandcrf 

Thank you for noticing this thread. I can confirm the same. With a single field, in harness, it fires updateView twice. With multiple fields, more. I have a hunch as to the reason.

While creating a composite address pcf control with 7 fields, I found that the number of updates also varied based on which field I was updating. With most of the fields I'd get 20 updateView calls. With Two of them, 30. On these fields, the difference was that I had a mismatch between the parameter name in the manifest and my code. IE, I believe I was sending back data including parameters that didn't exist.

I suspect the bug may be similar; the test harness itself includes input fields for each parameter, and may have a variable name typo, causing it to send an update containing an erroneous variable name. I suspect this is then evaluated against the properties bag as being different, triggering the additional updateView call. As noted, the CDS environment does not call updateView multiple times if your fieldnames are consistent, but it did when I had my own variable names wrong. I'm not sure if/how I can check this in the harness (above my current level), but Check the variable names used in the harness for consistency, and you may find your bug.

 

Ryan.

Erlandcrf
Microsoft
Microsoft

Hello again,

 

After done a research with our internal resources, we think that in order to provide a deeper troubleshooting and concrete answer it would be better for us that if you could submit a support ticket and take it from there.

 

You can also reference this same community post so once the investigation and resolution it's done, we can contribute to this same post and help more people in our community.

 

Please feel free to start a new support ticket by going to https://admin.powerplatform.microsoft.com/ and click on "Help + Support":

Erlandcrf_0-1596757567826.png

 

Thanks.

Done, ticket #120080725000178

rexkenley
Kudo Collector
Kudo Collector

@hajekj 

 

This is a known issue with the harness, it has been since last year. It is easily worked around by short circuiting the method if all of the incoming values are the same as the internal copies of said values.

Cheers!

davidjenkins
Advocate II
Advocate II

Any status updates for this?

I think one important detail here is that updateView() is called twice because the first call passes in the old value, and the second call passes in the new value.

 

Example:

  1. Control is rendered and initial value is "A".
  2. User interacts with your control, and control calls notifyOutputChanged().
    Control is trying to update value to "B".
  3. updateView() is called on control, but it passes in the value of "A".
    This happens only in sandbox, not in app.
  4. updateView() is called (again), passing in value of "B".
    This always happens.

 

This only happens in the sandbox when the control updates the property value. If the value is updated by hand in the sandbox sidebar then it behaves normally.

 

In many situations, this likely won't cause the developer any grief. In my case, however, I use state management and logic in updateView() that checks to see if my value has actually changed or updateView() is just being called because of notifyOutputChanged(), which doesn't work correctly in the sandbox because of this issue.

HemantG
Power Apps
Power Apps

Seems this is same as other thread we had - Re: updateView event fires 2x for every property u... - Power Platform Community (microsoft.com)

 

I have reached out to the PCF CLI team for help on this. 

 

hemant 

FlorianGrimm
Frequent Visitor

Hi
Do you use the pcf in CanvasApp? The fields are bound - Did you set a fomula for one or more fields?
I'm using output instead of bound - since I don't know how to detect if you can write the property.
Hope this helps

Stay healthy Flori

     

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,529)