<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Extension paint() called multiple times when switching from one sheet to another in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/Extension-paint-called-multiple-times-when-switching-from-one/m-p/2013074#M17710</link>
    <description>&lt;P&gt;There might be actions on the sheet actually... I'll do some tests on a clean sheet and see if anything changes, thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Dec 2022 10:21:54 GMT</pubDate>
    <dc:creator>master_t</dc:creator>
    <dc:date>2022-12-06T10:21:54Z</dc:date>
    <item>
      <title>Extension paint() called multiple times when switching from one sheet to another</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Extension-paint-called-multiple-times-when-switching-from-one/m-p/2004724#M17583</link>
      <description>&lt;P&gt;Hi everyone&lt;/P&gt;
&lt;P&gt;I'm developing an extension that needs to perform some async operations in the paint() function.&lt;/P&gt;
&lt;P&gt;From the documentation, I seem to understand that you can return a Promise from the paint() function, so I did something like this (code simplified for the question):&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="javascript"&gt;paint: function ($element, layout) {
	return new qlik.Promise((resolve, reject) =&amp;gt; {
		return myAsyncOperation(layout).then(result =&amp;gt; {
			process(result); //do my rendering
			return resolve();
		});
	});
}&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;When loading the page from scratch or when refreshing the page with F5 it all works as intended.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;However, I have a big issue &lt;/SPAN&gt;&lt;SPAN&gt;when switching from a sheet to another.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;In particular, when I switch from the sheet I'm at to another&amp;nbsp; that contains the extension, the paint() function gets called three times.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;This wouldn't be that big of an issue (other than the performance impact), but the big problem is that the second and third calls are made when the first call has not finished execution yet! And since the paint() function awaits for some promises, what happens is:&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;First call to paint() is made&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;First call executes until a promise is awaited inside the code&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Second call to paint() is made&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Second call executes until a promise is awaited inside the code&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Third call to paint() is made&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;First call resumes execution until the next promise in the code&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Second call resumes execution&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;...and so on, you get the idea...&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;First call terminates&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Second call terminates&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Third call terminates&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;SPAN&gt;This alternating execution makes it impossible for me to render the extension consistently, since the HTML code is manipulated simultaneously by the two calls, leaving it in an inconsistent state.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Now, I understand why the calls are alternating, that is how promises work... the real question here is: why is the paint() method called three times, and the second and third time in the middle of the execution of the first call? And why does it only happen when I switch from one sheet to the other?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;NOTE: I have an empty resize() method, so paint() is not getting called due to resize events.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 15 Nov 2022 14:23:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Extension-paint-called-multiple-times-when-switching-from-one/m-p/2004724#M17583</guid>
      <dc:creator>master_t</dc:creator>
      <dc:date>2022-11-15T14:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extension paint() called multiple times when switching from one sheet to another</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Extension-paint-called-multiple-times-when-switching-from-one/m-p/2007699#M17625</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/16584"&gt;@master_t&lt;/a&gt;&amp;nbsp;do you have any actions on the target sheet which could change something and then trigger the paint method? If you create an empty sheet, this continue to happen?&lt;/P&gt;&lt;P&gt;This looks like a weird behaviour, it would be better to have the Qlik App and extension source code for debugging. Can you share them?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 15:14:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Extension-paint-called-multiple-times-when-switching-from-one/m-p/2007699#M17625</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2022-11-22T15:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extension paint() called multiple times when switching from one sheet to another</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Extension-paint-called-multiple-times-when-switching-from-one/m-p/2013074#M17710</link>
      <description>&lt;P&gt;There might be actions on the sheet actually... I'll do some tests on a clean sheet and see if anything changes, thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 10:21:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Extension-paint-called-multiple-times-when-switching-from-one/m-p/2013074#M17710</guid>
      <dc:creator>master_t</dc:creator>
      <dc:date>2022-12-06T10:21:54Z</dc:date>
    </item>
  </channel>
</rss>

