{"id":31430,"date":"2022-04-21T17:06:10","date_gmt":"2022-04-21T11:36:10","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=31430"},"modified":"2022-10-14T12:05:52","modified_gmt":"2022-10-14T06:35:52","slug":"exclusive-sneak-peek-at-the-new-virtual-pcf-component","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2022\/04\/exclusive-sneak-peek-at-the-new-virtual-pcf-component\/","title":{"rendered":"Exclusive sneak peek at the new Virtual PCF Component"},"content":{"rendered":"<h2><strong>Introduction:<br \/>\n<\/strong><\/h2>\n<p>If you build PCF components then you must be aware that to create a standard control we render it on the container, which is provided in the PowerApps Component Framework.<\/p>\n<p>Microsoft has introduced a new type of control named Virtual Control. As the name suggests, this control creates and renders on the Virtual DOM.<\/p>\n<p>Virtual Components is where we can use the Virtual DOM and reuse the libraries i.e. Fluent UI and React from the PowerApps host. The primary advantage of the virtual component is its drastic performance improvements.<\/p>\n<p><strong>How they are different from Standard Control?<\/strong><\/p>\n<p>There are many differences between standard and virtual control. In Manifest xml file type, in the control tag, the control-type attribute is changed from standard to virtual i.e. <strong>control-type=&#8221;virtual&#8221;.<\/strong><\/p>\n<pre class=\"lang:css gutter:true start:1\">&lt;control namespace=\"Custom\" constructor=\"VirtualField\" version=\"0.0.1\" display-name-key=\"Virtual\" description-key=\"Virtual description\" control-type=\"virtual\"&gt;\r\n<\/pre>\n<p>In the resource tag, you will find React and Fluent UI dependency as well.<\/p>\n<pre class=\"lang:css gutter:true start:1\">&lt;resources&gt;\r\n\r\n&lt;code path=\"index.ts\" order=\"1\"\/&gt;\r\n\r\n&lt;platform-library name=\"React\" version=\"16.8.6\" \/&gt;\r\n\r\n&lt;platform-library name=\"Fluent\" version=\"8.29.0\" \/&gt;\r\n\r\n&lt;\/resources&gt;\r\n<\/pre>\n<p>In standard control, if there were many components, they would be bundled in its own React and Fluent UI for each component. This increases the footprints in your bundle.js, which increases the size of the same.<\/p>\n<p>However, in virtual control, components are added to the parent virtual DOM which has the dependency on React and Fluent UI. This will decrease the size of your bundle.js drastically. But, this also means that we need to make sure the correct version of Fluent UI and React is there to be used in the PCF components. In a future release, we might see the option to change the version of Fluent UI and React.<\/p>\n<p>We compared the size of virtual and standard control as shown in the images below.<\/p>\n<p><em>Note: They were the same control i.e. same code and components were added to them.<\/em><\/p>\n<p>Virtual Control \u2013<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-31433\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/1Virtual-PCF-Component-1.jpeg\" alt=\"Virtual PCF Component\" width=\"843\" height=\"170\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/1Virtual-PCF-Component-1.jpeg 689w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/1Virtual-PCF-Component-1-300x61.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/1Virtual-PCF-Component-1-660x133.jpeg 660w\" sizes=\"(max-width: 843px) 100vw, 843px\" \/><\/p>\n<p>Standard Control \u2013<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-31434\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/2Virtual-PCF-Component.jpeg\" alt=\"Virtual PCF Component\" width=\"840\" height=\"167\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/2Virtual-PCF-Component.jpeg 669w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/2Virtual-PCF-Component-300x60.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/2Virtual-PCF-Component-660x131.jpeg 660w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/p>\n<p>As we can see clearly, the difference between the sizes of the bundle.js file is quite prominent. As said earlier, this will affect the performance and you will notice it when you will use it in your CRM.<\/p>\n<p>Previously, in the index.ts file of standard control, the class was implementing StandardControl.<\/p>\n<pre class=\"lang:css gutter:true start:1\">export class LinearInputontrol implements ComponentFramework.StandardControl&lt;IInputs, IOutputs&gt; {<\/pre>\n<p>constructor(){}<\/p>\n<p>However, in virtual control, it will implement ReactControl, as we will be returning the react element.<\/p>\n<pre class=\"lang:css gutter:true start:1\">export class LinearInputontrol implements ComponentFramework.ReactControl&lt;IInputs, IOutputs&gt;{<\/pre>\n<p>constructor(){}<\/p>\n<p>This will also change the rendering of components from index.ts file. For standard control, we used to write our code as given below:<\/p>\n<pre class=\"lang:css gutter:true start:1\">public updateView(context: ComponentFramework.Context&lt;IInputs&gt;): void\r\n{\r\n\r\nReactDOM.render(React.createElement(App, {context}), this._container);\r\n\r\n}<\/pre>\n<p>Here we were creating an element and rendering it in the physical DOM i.e. this._container that we get in the init method, which is quite expensive in memory usage. Whereas in virtual control we just need to return the created element that will render on the Virtual DOM.<\/p>\n<pre class=\"lang:css gutter:true start:1\">public updateView(context: ComponentFramework.Context&lt;IInputs&gt;): React.ReactElement {\r\nconst props: AppProps = {context};\r\n\r\nreturn React.createElement(App, props);\r\n\r\n}<\/pre>\n<p><strong>How to create Virtual Control?<\/strong><\/p>\n<p>Now let us see how we can create virtual control. It is similar to how we create standard control. Below is the command to initialize PCF control.<\/p>\n<p><strong>Standard<\/strong> <strong>Control<\/strong> &#8211; pac pcf init -ns custom -n LinearInputControl -t field<\/p>\n<p><strong>Virtual Control<\/strong> &#8211; pac pcf init -ns custom -n LinearInputControl -t field -fw react -npm<\/p>\n<p>Here, -fw is the alias of &#8211;framework and -npm is to run the npm install command.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31435\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/3Virtual-PCF-Component.jpeg\" alt=\"Virtual PCF Component\" width=\"1053\" height=\"174\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/3Virtual-PCF-Component.jpeg 1053w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/3Virtual-PCF-Component-300x50.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/3Virtual-PCF-Component-1024x169.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/3Virtual-PCF-Component-768x127.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/3Virtual-PCF-Component-660x109.jpeg 660w\" sizes=\"(max-width: 1053px) 100vw, 1053px\" \/><\/p>\n<p>As we create react elements and render them on the virtual DOM so the framework will be <strong>React<\/strong>.<\/p>\n<p><em>Note: This is still in preview; we may see many more things coming up in this Virtual PCF.<\/em><\/p>\n<p>After running the above command, we will see our project as shown below:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31431\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/4Virtual-PCF-Component.jpeg\" alt=\"Virtual PCF Component\" width=\"498\" height=\"566\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/4Virtual-PCF-Component.jpeg 498w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/4Virtual-PCF-Component-264x300.jpeg 264w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/p>\n<p>A sample component (HelloWorld) will be created by default.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31436\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/5Virtual-PCF-Component-2.jpeg\" alt=\"Virtual PCF Component\" width=\"723\" height=\"400\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/5Virtual-PCF-Component-2.jpeg 723w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/5Virtual-PCF-Component-2-300x166.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/5Virtual-PCF-Component-2-660x365.jpeg 660w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/p>\n<p>The Virtual control can be used in the test harness as well.<br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-31428\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/6Virtual-PCF-Component-1.jpeg\" alt=\"Virtual PCF Component\" width=\"1356\" height=\"609\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/6Virtual-PCF-Component-1.jpeg 1356w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/6Virtual-PCF-Component-1-300x135.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/6Virtual-PCF-Component-1-1024x460.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/6Virtual-PCF-Component-1-768x345.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/6Virtual-PCF-Component-1-660x296.jpeg 660w\" sizes=\"(max-width: 1356px) 100vw, 1356px\" \/><\/p>\n<p>If we dive deep into the bundle.js then we can see that the host is providing the libraries of Fluent UI and React. Hence, the other components will not need to bring their fluent UI and React with them, which results in the reduction of size of the bundle js.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31427\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/7Virtual-PCF-Component-1.jpeg\" alt=\"Virtual PCF Component\" width=\"1155\" height=\"209\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/7Virtual-PCF-Component-1.jpeg 1155w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/7Virtual-PCF-Component-1-300x54.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/7Virtual-PCF-Component-1-1024x185.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/7Virtual-PCF-Component-1-768x139.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/04\/7Virtual-PCF-Component-1-660x119.jpeg 660w\" sizes=\"(max-width: 1155px) 100vw, 1155px\" \/><\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>I would say it would increase the performance of our components exceptionally. In addition, it is still in preview so I will recommend not putting this in your production soon.<\/p>\n<p>To conclude, we learned how we can create Virtual PCF components and how they are different from the standard control.<\/p>\n<h2 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">Save 1-2 hours or $800 monthly on scheduling and managing business travel with a geo-mapping App!<\/div><\/div><\/h2>\n<p><em><strong><a href=\"https:\/\/bit.ly\/3ELX45j\" target=\"_blank\" rel=\"noopener noreferrer\">Maplytics<\/a> <\/strong>\u2013 Integrate Map with Dynamics 365 CRM and visualize data on the map, manage sales territories, auto-schedule appointments, get optimized travel routes, track field reps in real-time, and more<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: If you build PCF components then you must be aware that to create a standard control we render it on the container, which is provided in the PowerApps Component Framework. Microsoft has introduced a new type of control named Virtual Control. As the name suggests, this control creates and renders on the Virtual DOM.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2022\/04\/exclusive-sneak-peek-at-the-new-virtual-pcf-component\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1894,44,1929,2361],"tags":[2595],"class_list":["post-31430","post","type-post","status-publish","format-standard","hentry","category-dynamics-365-virtual-agent","category-power-apps","category-pcf","category-technical","tag-virtual-pcf-component"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/31430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=31430"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/31430\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=31430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=31430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=31430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}