FlexGrid disposing issue with React 18

Posted by: omarovd on 1 October 2024, 4:15 pm EST

  • Posted 1 October 2024, 4:15 pm EST - Updated 1 October 2024, 4:20 pm EST

    Hi folks!

    We are migrating our project to React 18 and started using wijmo package 5.20221.842 version.

    We have strict content policy applied (no inline styles) but for the components, where FlexGrid is presented - we face error about violation of the policy (pls see attachment) (that happens, once we destroy parent component).

    Is there a possibility to prevent FlexGrid emit inline styles?

  • Posted 4 October 2024, 5:13 am EST

    Hi Dulat,

    Apologies for the inconvenience!

    Unfortunately, this is a limitation of the product. Wijmo does not comply with the style-src Content Security Policy as it uses inline CSS for applying style to many of it’s controls. However, it does support the script-src policy so if you are using the default-src policy or style-src policy, I would suggest you to just use script-src as default-src policy includes style-src.

  • Posted 4 October 2024, 4:24 pm EST

    Out of curiosity: why flexGrid requires to apply style (in particular - width size) at it destroy moment? Only this behavior triggers our security-watchdog to report policy violation. It is flexGrid destroy process, isn’t it? What is the benefit or convenience it provides, if at next discreet of time flexGrid disappears?

  • Posted 7 October 2024, 3:15 am EST

    Hi Dulat,

    The inline CSS used in Flex Grid is applied at the time of rendering. I am not sure why is this error being thrown in your application at the time when the grid is destroyed I would require a runnable sample from you so I can investigate further on this. In my testing, the issue occurs when the grid is initialized. This variation might be occurring due to different environment specifications.

    Please refer to the following sample application: https://stackblitz.com/edit/react-wepabm-sxaqez?file=index.html

    The style-src rule suggests not to define styles on the style attribute of elements or style tag under html. In the Wijmo source code style attribute related operations are extensively used and many Framework/Libraries/UI Tools like Tailwind, which is currently the most popular CSS tool on the market, follow the same approach. At the moment, It is very difficult us to meet this style-src rule as it would be a huge task.

    I would suggest you to allow inline CSS in your CSP header(see the above shared sample link).

  • Posted 7 October 2024, 12:42 pm EST - Updated 7 October 2024, 12:47 pm EST

    Hi!

    Here is the problematic spot in our case:



    I tried to reproduce it on the forked https://stackblitz.com/edit/react-wepabm-sxaqez?file=index.html

    But obviously - it doesn’t flagging error, since it is not related to syntax or any other brutal code violation.

    As you can see on the screenshot - at the moment of the control disposing - it applies the width size.

  • Posted 8 October 2024, 8:43 am EST

    Hi Dulat,

    I tried to reproduce your issue at my end but it seems that on destroy the setAttribute for ‘style’ was only called when I set inline style for grid but that is not a valid use case for your scenario, so I am not sure how to reproduce this issue. Please share the modified sample reproducing the issue so we can get back to you accordingly.

    As for why are using setAttribute function in the Dispose method… I am not really sure which is why I have escalated this case to the development team to get their input on the same[WJM-35098]. I will get back to you once I have any updates on the same.

    In any case, since style-src content security policy is not supported in Wijmo, I would suggest you to not use it on pages using Wijmo.

  • Posted 11 October 2024, 2:41 am EST

    Hi Dulat,

    I have an update from the development team. As I discussed with the development team, on dispose it’s important to return the DOM element (the host element) to its original state before the control is removed. This ensures that the element stays intact and doesn’t lose any attributes or get altered after the control is disposed of.

    Applying original element properties on dispose makes sure the element has returned to it’s original state and can be used again to create the grid or perform other logical tasks.

    I hope this clears up any confusion.

    Regards,

    Akshay

  • Posted 11 October 2024, 10:29 am EST - Updated 11 October 2024, 10:49 am EST

    Hi Akshay!

    Actually, this answer leads to next questions:

    Usually default properties are applied in the constructor. What if I need few Grids on the page? Does that mean, without calling “dispose” process on the wijmo source-control, I’ll receive a grid’s instance for my 2-nd component not in default shape?

    Question 2:

    The exercise with returning wijmo control in original shape means: once created, it is ready to be reused at any moment, isn’t it? But what if I don’t need it anymore? Is it not a direct sign of memory leak, if there are unused objects in the memory, accumulating and consuming more and more limited space?

    It would be something deserving attention: the CSP complains only on dispose cycle of the wijmo control. All other control’s lifecycle methods (including animation) work safely. Maybe it worth to revise logic of dispose and tune it to be compliant with other methods? Or provide method to manage it from outside?

    On the same note - this problem didn’t exist on the 2021 version of the wijmo products

Need extra support?

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

Learn More

Forum Channels