dataverse-frontend icon indicating copy to clipboard operation
dataverse-frontend copied to clipboard

double network calls in React

Open pdurbin opened this issue 3 months ago • 4 comments

@g-saracca shared with me the following tip for disabling double network calls in React:

% git diff src/index.tsx
diff --git a/src/index.tsx b/src/index.tsx
index 534a26ff..ff2b7fc1 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -4,7 +4,7 @@ import { KcPage } from './keycloak-theme/kc.gen'
 const AppEntrypoint = lazy(() => import('./index.app'))

 createRoot(document.getElementById('root') as HTMLElement).render(
- <StrictMode>
+ <>
     {window.kcContext ? (
       <KcPage kcContext={window.kcContext} />
     ) : (
@@ -12,5 +12,5 @@ createRoot(document.getElementById('root') as HTMLElement).render(
         <AppEntrypoint />
       </Suspense>
     )}
- </StrictMode>
+ </>
 )

This change should not be committed but it's helpful in development to reduce the noise.

We should explain this in the dev guide or make it a config option, if possible.

pdurbin avatar Oct 10 '25 15:10 pdurbin

I don't know if we should be encouraging developers to comment out StrictMode during development, it's meant as a safe guard to detect bugs and unexpected side effects in the code. If devs comment it out, that benefit goes away. Sometimes it does help to temporarily remove it, but that's easy enough to do in your code locally, as you mentioned. Just my 2 cents!

ekraffmiller avatar Oct 17 '25 15:10 ekraffmiller

Yes, I agree with @ekraffmiller, it should only be commented out if you are debugging api calls in some way to reduce noise in the browser network tab.

g-saracca avatar Oct 17 '25 16:10 g-saracca

Yes, exactly! Some sort of config option would be great!

pdurbin avatar Oct 17 '25 17:10 pdurbin

And just to be clear, this behaviour is only in dev mode, wont happen when building the app to be deployed.

g-saracca avatar Oct 17 '25 17:10 g-saracca