iway1 / trpc-panel

MIT License
663 stars 50 forks source link

DEV: Query re-runs if code changes and reload occurs #8

Closed AshSimmonds closed 1 year ago

AshSimmonds commented 1 year ago

Possibly a non-issue, but if you're doing some "endpoint" testing, then you change some code and reload the panel page it will re-run that query.

Issues may be if the endpoint isn't idempotent or is destructive etc, may lead to weird outcomes during testing/debugging.

iway1 commented 1 year ago

I've noticed this, don't think it'd likely cause issues, but you're right would be better if it only ran queries when the user presses the execute button.

I think there is a React Query setting to turn this off, probably one of refetchOnReconnect: false and/or refetchOnWindowFocus: false

AshSimmonds commented 1 year ago

Where would that be set, is it beyond the usual appRouter? Just tried these settings and none of them seem to matter - btw it does the re-run just when the page itself gets focus too, which my normal pages do not so it's getting that setting elsewhere.


    config() {
        return {
            queryClientConfig: {
                defaultOptions: {
                    queries: {
                        // staleTime: 1000 * 60 * 5, // 5 minutes
                        refetchOnWindowFocus: false,
                        retry: false,
                        refetchOnReconnect: false,
                        refetchOnMount: false,
                        retryOnMount: false,
                    },
                },
            },
            url: `${getBaseUrl()}/api/trpc`,
            transformer,
        }
    },
    ssr: false,
})```
iway1 commented 1 year ago

That's weird I would think that would work, you could try changing it in the ProcedureForm component (where useQuery is getting called) and pass the options there directly to the hook