Skip to content
Source
Sign inSign up
TanStack/query

Newly added `use client` directives don't work as expected in RSC #4876

Send to my agent
ClosedChristianIvicevic(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

In #4738 the use client directive was added to client-side files but trying to use the React Query Devtools is throwing errors attached below:

error - ./node_modules/@tanstack/react-query-devtools/build/lib/Explorer.mjs
Attempted import error: 'useState' is not exported from 'react' (imported as 'React').

Import trace for requested module:
./node_modules/@tanstack/react-query-devtools/build/lib/Explorer.mjs
./node_modules/@tanstack/react-query-devtools/build/lib/devtools.mjs
./node_modules/@tanstack/react-query-devtools/build/lib/index.mjs
./src/app/layout.tsx

image

Your minimal, reproducible example

https://github.com/ChristianIvicevic/tanstack-query-rsc-use-client-issue

Steps to reproduce

  1. npm install
  2. npm run dev
  3. Open the application

Expected behavior

No server error with the devtools being available.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Not relevant.

TanStack Query version

4.23.0

TypeScript version

No response

Additional context

No response

  1. I think we forgot to add 'use client' to the index file of the devtools:

    https://github.com/TanStack/query/blob/d4fa2b98cf1b6a1f8a2722f5983e71a199c80c85/packages/react-query-devtools/src/index.ts

    Would you like to contribute that to see if that fixes it?

    Workaround: It works if you move the devtools rendering to a client component like Providers:

    https://codesandbox.io/p/sandbox/upbeat-sun-b9pq0q?file=%2Fsrc%2Fapp%2Fclient.tsx&selection=%5B%7B%22endColumn%22%3A17%2C%22endLineNumber%22%3A12%2C%22startColumn%22%3A17%2C%22startLineNumber%22%3A12%7D%5D

  2. TkDodo added labelsbug

  3. TkDodo added labelspackage: react-query-devtools

  4. I created #5041 to solve it, my first ever one for TanStack :)

  5. TkDodo closed this

Sign in to join this conversation.