Error when lazy loading the library

Stimulsoft Reports.JS discussion
Post Reply
csrt
Posts: 49
Joined: Thu Jan 17, 2019 12:38 pm

Error when lazy loading the library

Post by csrt »

Hello. I am trying to implement the lazy loading approach, described in this post: viewtopic.php?t=57333
The approach itself works, but when loading, it keeps firing an error: stimulsoft.reports.js:43 Uncaught TypeError: Cannot redefine property: stimulsoft, which comes from here: Object.defineProperty(Number.prototype,"stimulsoft",{get:function(){return new Stimulsoft.System.StiNumber(this.valueOf())}...

To mention that when sync loading - it works just fine.
Any ideas how to fix the lazy loading error?
Lech Kulikowski
Posts: 6244
Joined: Tue Mar 20, 2018 5:34 am

Re: Error when lazy loading the library

Post by Lech Kulikowski »

Hello,

Unfortunately, we can not provide any solutions for that issue. We do not test lazy loading.

Thank you.
mrapi
Posts: 277
Joined: Sat Dec 20, 2008 1:08 am

Re: Error when lazy loading the library

Post by mrapi »

Hello,I think you are loading the scripts more than once,in link above there is a check for that.that's our updated code that works,we added some loading time:

Code: Select all

@Injectable()
export class GeneralService {
  private stiScrpLoaded = false;
.......
  fnIsMobile(): boolean {
        return window.screen.width < 500;
    }
   ....
  public loadStimulScripts(): Promise<any> {
    return new Promise((resolve) => {
      if (!this.stiScrpLoaded) {                     //here
        this.loadScript('assets/stimulsoft.viewer.pack.js');
        this.loadScript('assets/stimulsoft.reports.pack.js');
        this.stiScrpLoaded = true;
        setTimeout(() => {
          resolve();
        }, (fnIsMobile() ? 5100 : 2500));

      } else {
        resolve();
      }
    });
}

  private loadScript(url: string) {
    const node = document.createElement('script');
    node.src = url;
    node.type = 'text/javascript';
    node.async = true;
    document.getElementsByTagName('head')[0].appendChild(node);
  }


maybe you find useful info there https://stackoverflow.com/questions/344 ... in-angular

csrt wrote: Tue Jan 14, 2020 7:01 pm ..
Any ideas how to fix the lazy loading error?
Last edited by mrapi on Mon Jan 20, 2020 6:33 am, edited 1 time in total.
Lech Kulikowski
Posts: 6244
Joined: Tue Mar 20, 2018 5:34 am

Re: Error when lazy loading the library

Post by Lech Kulikowski »

Hello,

Thank you for the provided information.
csrt
Posts: 49
Joined: Thu Jan 17, 2019 12:38 pm

Re: Error when lazy loading the library

Post by csrt »

mrapi wrote: Sat Jan 18, 2020 6:14 am Hello,I think you are loading the scripts more than once,in link above there is a check for that.that's our updated code that works,we added some loading time:

Code: Select all

@Injectable()
export class GeneralService {
  private stiScrpLoaded = false;
.......
  fnIsMobile(): boolean {
        return window.screen.width < 500;
    }
   ....
  public loadStimulScripts(): Promise<any> {
    return new Promise((resolve) => {
      if (!this.stiScrpLoaded) {                     //here
        this.loadScript('assets/stimulsoft.viewer.pack.js');
        this.loadScript('assets/stimulsoft.reports.pack.js');
        this.stiScrpLoaded = true;
        setTimeout(() => {
          resolve();
        }, (fnIsMobile() ? 5100 : 2500));

      } else {
        resolve();
      }
    });
}

  private loadScript(url: string) {
    const node = document.createElement('script');
    node.src = url;
    node.type = 'text/javascript';
    node.async = true;
    document.getElementsByTagName('head')[0].appendChild(node);
  }


maybe you find useful info there https://stackoverflow.com/questions/344 ... in-angular

csrt wrote: Tue Jan 14, 2020 7:01 pm ..
Any ideas how to fix the lazy loading error?
Hello, thank you for your answer - you were right
Andrew
Posts: 4104
Joined: Fri Jun 09, 2006 3:58 am

Re: Error when lazy loading the library

Post by Andrew »

Hello,

Okay, you are welcome!
Post Reply