Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add eslint-plugin-no-typeof-window-undefined #4587

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Expand Up @@ -6,6 +6,7 @@
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"plugin:no-typeof-window-undefined/recommended",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's better to specify this plugin config (with a single rule) or specify it in plugins and enable this rule specifically.

"react-app",
"prettier"
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -63,6 +63,7 @@
"eslint-plugin-flowtype": "5.x",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "6.x",
"eslint-plugin-no-typeof-window-undefined": "^0.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-promise": "^4.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query-devtools/src/devtools.tsx
Expand Up @@ -282,7 +282,7 @@ export function ReactQueryDevtools({

run()

if (typeof window !== 'undefined') {
if (typeof document !== 'undefined') {
window.addEventListener('resize', run)

return () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-query-devtools/src/useMediaQuery.ts
Expand Up @@ -3,14 +3,14 @@ import * as React from 'react'
export default function useMediaQuery(query: string): boolean | undefined {
// Keep track of the preference in state, start with the current match
const [isMatch, setIsMatch] = React.useState(() => {
if (typeof window !== 'undefined') {
if (typeof document !== 'undefined') {
return window.matchMedia(query).matches
}
})

// Watch for changes
React.useEffect(() => {
if (typeof window !== 'undefined') {
if (typeof document !== 'undefined') {
// Create a matcher
const matcher = window.matchMedia(query)

Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/QueryClientProvider.tsx
Expand Up @@ -28,7 +28,7 @@ function getQueryClientContext(
if (context) {
return context
}
if (contextSharing && typeof window !== 'undefined') {
if (contextSharing && typeof document !== 'undefined') {
if (!window.ReactQueryClientContext) {
window.ReactQueryClientContext = defaultContext
}
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query/src/QueryClientProvider.tsx
Expand Up @@ -32,7 +32,7 @@ function getQueryClientContext(
if (context) {
return context
}
if (contextSharing && typeof window !== 'undefined') {
if (contextSharing && typeof document !== 'undefined') {
if (!window.SolidQueryClientContext) {
window.SolidQueryClientContext = defaultContext
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-query/src/vueQueryPlugin.ts
Expand Up @@ -38,7 +38,7 @@ export const VueQueryPlugin = {
if ('queryClient' in options && options.queryClient) {
client = options.queryClient
} else {
if (options.contextSharing && typeof window !== 'undefined') {
if (options.contextSharing && typeof document !== 'undefined') {
if (!window.__VUE_QUERY_CONTEXT__) {
const clientConfig =
'queryClientConfig' in options
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.