XantreDev / preact-signals

Preact Signals: Supercharge your React/Preact development! Unleash the power of reactive programming with hooks, components, a TanStack query adapter, and more. Code smarter, not harder
https://preact-signals.netlify.app/#/
MIT License
70 stars 1 forks source link

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'value') #194

Closed victor-gapeev closed 2 months ago

victor-gapeev commented 2 months ago

Hi, i got next bug with last @preact-signals/query version:

screenshot1

My custom hook to wrap Read entity queries:

export default function useREntity<E, Q>(prefix: EntityList, query: Partial<Q> = {}) {
    const router = useLocation()
    const { logout } = useUser()

    const path = `/${prefix}`

    const q = useQuery$(() => ({
        queryFn: async ({ signal }) => {
            if (!signal?.aborted) {
                const response = await getRequest<E, Q>(path, query, signal)
                return response
            }
        },
        queryKey: [prefix, ...Object.values(query).map((q) => q + "")],
    }))

    if (q.data && !q.data.result) {
        if (q.data.code == 401) {
            logout()
            router.route("/login")
        }
    }

    return q
}

Error in preact code: image

I also use the preact-iso package to create spa routing.

Update: This bug happens only after the first load, if I switch pages and return back, I can use filters and other parts, and everything works fine.

XantreDev commented 2 months ago

It's a strange behavior. I will investigate it

victor-gapeev commented 2 months ago

Im sorry, its my fault. Above in my code I accidentally store useSignal result in global variables, which leads to strange bugs like this.