Skip to content

Commit

Permalink
feat(react-query): preserve 'use client' directives (#5161)
Browse files Browse the repository at this point in the history
* chore: preserve 'use client' directive in unbundled builds

* fix(react-query): add 'use client' to files missing it

* chore: lock version for rollup-plugin-preserve-directives
  • Loading branch information
Ephem committed Mar 20, 2023
1 parent fe0ae80 commit 017867e
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"react-dom-17": "npm:react-dom@^17.0.2",
"rimraf": "^3.0.2",
"rollup": "^2.70.2",
"rollup-plugin-preserve-directives": "0.1.0",
"rollup-plugin-size": "^0.2.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.6.0",
Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/errorBoundaryUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import type {
DefaultedQueryObserverOptions,
Query,
Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/reactBatchedUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
'use client'
import * as ReactDOM from 'react-dom'
export const unstable_batchedUpdates = ReactDOM.unstable_batchedUpdates
1 change: 1 addition & 0 deletions packages/react-query/src/useBaseQuery.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import * as React from 'react'
import { useSyncExternalStore } from './useSyncExternalStore'

Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/useInfiniteQuery.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import type {
QueryObserver,
QueryFunction,
Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/useIsFetching.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import * as React from 'react'
import type { QueryKey, QueryFilters } from '@tanstack/query-core'
import { notifyManager, parseFilterArgs } from '@tanstack/query-core'
Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/useIsMutating.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import * as React from 'react'
import { useSyncExternalStore } from './useSyncExternalStore'

Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/useMutation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import * as React from 'react'
import { useSyncExternalStore } from './useSyncExternalStore'

Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/useQueries.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import * as React from 'react'
import { useSyncExternalStore } from './useSyncExternalStore'

Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import type { QueryFunction, QueryKey } from '@tanstack/query-core'
import { parseQueryArgs, QueryObserver } from '@tanstack/query-core'
import type {
Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/useSyncExternalStore.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
// Temporary workaround due to an issue with react-native uSES - https://github.com/TanStack/query/pull/3601
import { useSyncExternalStore as uSES } from 'use-sync-external-store/shim/index.js'

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.

4 changes: 4 additions & 0 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import replace from '@rollup/plugin-replace'
import nodeResolve from '@rollup/plugin-node-resolve'
import commonJS from '@rollup/plugin-commonjs'
import path from 'path'
import preserveDirectives from 'rollup-plugin-preserve-directives'

type Options = {
input: string | string[]
Expand Down Expand Up @@ -285,6 +286,7 @@ function mjs({
commonJS(),
nodeResolve({ extensions: ['.ts', '.tsx', '.native.ts'] }),
forceDevEnv ? forceEnvPlugin('development') : undefined,
preserveDirectives(),
],
}
}
Expand Down Expand Up @@ -324,6 +326,7 @@ function esm({
commonJS(),
nodeResolve({ extensions: ['.ts', '.tsx', '.native.ts'] }),
forceDevEnv ? forceEnvPlugin('development') : undefined,
preserveDirectives(),
],
}
}
Expand Down Expand Up @@ -375,6 +378,7 @@ function cjs({
preventAssignment: true,
delimiters: ['', ''],
}),
preserveDirectives(),
],
}
}
Expand Down

0 comments on commit 017867e

Please sign in to comment.