TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
40.1k stars 2.69k forks source link

fix(query-core): Before use globalThis, check its existence. #7310

Closed kaikidd closed 3 weeks ago

kaikidd commented 3 weeks ago

I'm utilizing @tanstack/react-query within a React project operating in a unique environment. However, during runtime, the global object 'globalThis' is not available, causing errors to be displayed in the console and bringing the entire application down. I believe that implementing a check for the existence of 'globalThis' before its usage could resolve this issue.

截屏2024-04-20 23 33 48
vercel[bot] commented 3 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **query** | ⬜️ Ignored ([Inspect](https://vercel.com/tanstack/query/2woF5voi4qwCzsdMrZjTrVUKx4HC)) | [Visit Preview](https://query-git-fork-kaikidd-fix-isserver-tanstack.vercel.app) | | Apr 20, 2024 4:47pm |
codesandbox-ci[bot] commented 3 weeks ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit db71676a953c2511c4be2b4e63dae288ca9d8dd1:

Sandbox Source
@tanstack/query-example-angular-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration
TkDodo commented 3 weeks ago

what kind of environment are you working in please? globalThis should be available in all envs that we support:

kaikidd commented 3 weeks ago

I use @tanstack/react-query in @tarojs/cli(https://github.com/NervJS/taro), it is a runtime framwork tailored for developing specialized mini-applications designed to run on Android and IOS application in China. The customized runtime environment encompasses most browser environments, but there are exceptions, such as the absence of 'globalThis'. I use @tanstack/react-query correctly before a pull request fix(query-core): Replace the deprecated 'window' with 'globalThis' fo...(https://github.com/TanStack/query/pull/7029). @tanstack/react-query version 5.26.3 works fine for me.

TkDodo commented 3 weeks ago

The customized runtime environment encompasses most browser environments, but there are exceptions, such as the absence of 'globalThis'.

globalThis is a standard that was introduced to avoid checks for window, global or self in different environments. It's supposed to be available in all modern environments.

If it's not available for you, please add a polyfill that will set globalThis to, idk, window or an empty object or whatever you want. As a last resort, you can also patch-package react-query.