Select to view content in your preferred language

calcite-components-react with Vite - errors during HMR

758
6
04-01-2024 12:18 AM
AndresKasekamp
Emerging Contributor

I have a problem using calcite-components-react with Vite dev server in HMR mode. The components, when applying changes or even on initial load, seem to get duplicated.

For example, the layerlist as shown here:

AndresKasekamp_0-1711955457391.png

AndresKasekamp_1-1711955618800.png

 

The current workaround is destroying the view with view.destroy() in useEffect cleanup, and then doing a full reload when changes are made, this at least assures that the components do not get duplicated, but it defeats the purpose of using HMR.

How it should look like:

AndresKasekamp_2-1711955679858.png

There are no problems in production build.

I have re-created a minimal example here:

https://github.com/AndresKasekamp/calcite-arcgis-hmr

0 Kudos
6 Replies
imritanshu
Regular Contributor

@AndresKasekamp 

hey, the reason is you are running you app in strict mode.

imritanshu_0-1711963654373.png

 

comment these lines and app should work fine.

 

Also one more observation, every variable you are storing in state, which may cause issue as application will grow. Try state only where it is must. Else you can simply store values without state also.

 

Thanks. 

 

if solution works please mark it as answer.

0 Kudos
AndresKasekamp
Emerging Contributor

Disabling StrictMode does not work.

0 Kudos
imritanshu
Regular Contributor

Probably you are doing something wrong. I cloned your sample and commented the strict mode. It is working without any issue.

imritanshu_0-1711968528934.png

Have a look.

0 Kudos
imritanshu
Regular Contributor
0 Kudos
AndresKasekamp
Emerging Contributor

The first render is okay, so it would be the same as calling view.destroy(). However, when you modify App.jsx file in any way with dev server running (comments, new line, imports, etc), then it will cause the components to behave unexpectedly.

0 Kudos
AndyGup
Esri Regular Contributor

Hi @AndresKasekamp  you'll need to do further testing by removing '@arcgis/core' functionality and calcite elements one-by-one to try and find the root cause. Otherwise there's too much going on in the sample including the calcite react wrapper, calcite-panel, calcite-shell, calcite-shell-panel and various '@arcgis/core' modules.

0 Kudos