Error when (re)rendering web designer

Posted by: ewan.johnstone on 13 April 2022, 5:57 am EST

    • Post Options:
    • Link

    Posted 13 April 2022, 5:57 am EST

    Greetings,

    I am trying to integrate the ActiveReports web designer into an existing project. I have the following code in a React component and when I first render the component it works fine but if I leave and then come back to the component (rerendering it) I get the error message from the GrapeCity.ActiveReports.WebDesigner.renderApplication method:

    “Error: CoreDocumentsAPI[id=designer] already exists, use CoreDocumentsAPI.of(id)”

    So it seems the designer is not being cleaned up when the component is disposed. But it’s not clear to me from the documentation how I’m meant to clean up afterwards, only the viewer seems to have a destroy method. How can I prevent this error? I am using 15.2.2 of ar-designer.

    
    import '@grapecity/ar-designer/dist/web-designer.css';
    import '@grapecity/ar-designer/dist/web-designer.js';
    import stringify from 'json-stable-stringify';
    import React, { useEffect } from 'react';
    import './ReportDesigner.scss';
    type Props = {
      mode: ReportHeaderEditMode;
      onCancel: () => void;
    };
    
    export enum ReportHeaderEditMode {
      RemittanceAdvice = 1,
      ExternallyViewable = 2,
    }
    const ReportDesigner = (props: Props) => {
      useEffect(() => {
        const params = stringify({ mode: props.mode });
        const reportPath = `Report/${0}/${params}/${false}`;
        const options = (window as any).GrapeCity.ActiveReports.WebDesigner.createDesignerOptions();
        options.reportInfo = { id: reportPath, name: reportPath };
        options.reportItemsFeatures.table.autoFillFooter = true;
        options.saveButton.visible = true;
        options.saveAsButton.visible = true;
        options.documentation.home =
          'https://www.grapecity.com/activereports/docs/v15/online-webdesigner/overview.html';
        options.server.url = 'ar';
        (window as any).GrapeCity.ActiveReports.WebDesigner.renderApplication('designer', options);
      }, []);
    
      return <div id="designer"></div>;
    };
    
    export default ReportDesigner;
    
    
    
  • Posted 21 April 2022, 3:44 am EST

    Hi Ewan,

    Please use the apiOf() method to get the DesignerApi of the previously created instance.

    For this you would have to use the WebDesignerV2 api to create the designer. Use this method to get the instance of already created Designer when the user navigate to another component and come back to the designer component. If the object is null or undefined, then create the WebDesigner again, else not. The code for this would be something like:

    var designerobj = GrapeCity.ActiveReports.WebDesignerV2.apiOf("designer-id")
    if(designerobj == undefined || designerobj == null)
    {
        GrapeCity.ActiveReports.WebDesignerV2.create('designer-id', designerOptions);
    }
    

    For more information on this please refer to the following link:

    https://www.grapecity.com/activereportsnet/docs/latest/online/web-designer-plugins-api.html#:~:text=create()-,apiOf(),-DesignerApiV2

    Regards,

    Akshay

  • Posted 9 May 2022, 10:41 am EST

    Hi Akshay,

    This gets rid of the error when opening the component for the second time, however the designer no longer renders i.e there is no designer component inside the div with id=designer-id. It seems like the only way to rerender the designer is by calling the create method which just leads to the issue I had at the start. Is there a way of manually cleaning up the designer from the first render so that I can create a fresh designer each render?

  • Posted 13 May 2022, 12:42 am EST

    Hi Ewan,

    Please provide us with a runnable sample replicating this behavior so we can investigate this issue on our end and reply accordingly.

    Regards,

    Akshay

  • Posted 13 May 2022, 6:30 am EST

    Hi Akshay,

    I have attached a minimal working example that demonstrates the issue using create-react-app.

    DesignerExample.zip

  • Posted 16 May 2022, 12:37 pm EST

    Hello Ewan,

    I was able to replicate this behavior on my end and have escalated this issue to the development team. I will revert back to you once I have any information from them. [AR-28718]

    Regards,

    Akshay

  • Posted 26 August 2022, 4:36 am EST

    Hi Akshay,

    Any update on the task AR-28718?

  • Posted 29 August 2022, 10:02 am EST

    Hi Ewan,

    Apologies for the delay. I have discussed this issue with the development team. We have added the destroy method in ActiveReports version 16.1(and higher). For this please refer to the following lines of code:

    	GrapeCity.ActiveReports.WebDesignerV2.destroy('designer-id');
    

    Please upgrade your application to ActiveReports 16.1 or higher and then you should be able to use this method to destroy the designer instance.

    For downloading the latest version of ActiveReports please refer to the following link:

    https://cdn.grapecity.com/ActiveReports/ar16/ActiveReports-v16.2.0.msi

    Regards,

    Akshay

  • Posted 5 September 2022, 10:50 am EST

    Hi Akshay,

    Glad to see that 16.2 is finally out.

    I’ve had a look today but I can’t see the destroy method you refer to.

    Calling the above method doesn’t seem to do anything as I get the error: “Settings[id=designer-id] already exists. Use DesignerCore.settings.of(id)”

    Inspecting WebDesignerV2 via console.log I only see the methods create(), apiOf() and addLanguage() which are the only methods listed in the api documentation. I can find no reference to a destroy method in the api documentation.

    Moreover inspecting GrapeCity.ActiveReports.WebDesignerV2.destroy via console.log returns undefined.

    Are you absolutely sure this method was added?

  • Posted 7 September 2022, 6:04 am EST

    Hi Ewan,

    I have discussed on this issue with the development team. The destroy method is added to ActiveReports 16.1.3 as well. Currently, there seems to be an issue with ActiveReports 16.2 destroy method. We are working on this issue for now I would suggest you to downgrade to ActiveReports 16.1.3 if you want to use the destroy method.

    To download ActiveReports 16.1.3 please use the following link:

    https://cdn.grapecity.com/ActiveReports/ar16/ActiveReports-v16.1.3.msi

    Apologies for the inconvenience.

  • Posted 9 September 2022, 10:54 am EST

    Hi Akshay,

    I reverted my designer version to v.16.1.3 and I did find the destroy method present on the WebDesignerV2 (side note, why are there two versions of the WebDesigner class?).

    However, if I create a designer with id “designer”, then call GrapeCity.ActiveReports.WebDesignerV2.destroy(‘designer’)

    I get the error:

    "Uncaught error: There is no Designer instance with “designer” id ".

    But then when I create the designer again I get the usual error:

    “CoreSettingsAPI[id=designer] already exists, use CoreSettingsAPI.of(id)”.

    So the destroy methods seems to not be able to locate the correct instance.

    Is this the issue which lead it to be removed in v16.2? Will I need to wait until a new version before this is fixed?

  • Posted 12 September 2022, 4:17 pm EST

    Hi Ewan,

    >> why are there two versions of the WebDesigner class?

    I have forwarded this question to the development team for the answer.[AR-29372]

    I tested for this at my end and I wasn’t able to replicate this behavior. I have attached a sample project for reference.

    Please share a runnable sample replicating this issue or edit the attached sample application such that it reproduces this behavior and send it back to us so we can reproduce this issue at our end and investigate further on this.

    DestroyMethodSample.zip

  • Posted 13 September 2022, 4:45 am EST

    Hi Ewan,

    I have an update from the development team. The WebDesignerV2 contains the new API and WebDesigner keeps previous version of API for the backward compatibility.

    I hope this answers your question.

  • Posted 13 September 2022, 6:55 am EST

    Hi Akshay,

    I ran the example code that you provided and it worked fine.

    I modified the example code that I shared earlier to include the new changes and I am getting the error. The key difference seems to be that in my example, I am showing and hiding the component dynamically (this is the behaviour in our program for screens like this). I’ve attached the new code, hopefully you can reproduce it on your end.

    designExampleV2.zip

  • Posted 17 September 2022, 1:28 pm EST

    Hi Ewan,

    Thanks for the sample! I was able to reproduce this issue with your sample at my end as well. I tried to recreate your issue in ASP.Net project and the application ran perfectly and the error you mentioned only occurred when I tried to create the designer with the same id when it was already existing in the application.

    After spending hours to debug this issue in your sample I realized that you are using StrictMode in your React v18 application. React v18 StrictMode forces double rendering of a component in the same tick in contract to previous react versions. It means that ActiveReports component is called to be mounted, unmounted and mounted again in the same tick. But ActiveReports component postpones unmounting for next tick. So second mounting takes place on mounted component which leads to error.

    To fix this issue I would suggest you to either not use StrictMode or if you want to use StrictMode you would have to destroy the designer just before you would call the create() method.

    I have also shared an enhancement request with the development team to dispose the designer first, every time create method is called. However, ActiveReports is a product compatible with multiple different technologies and not just React I am not really sure if this will be implemented in the near future.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels