"isServer" check breaks some environments
In Raycast, I used to be able to auto-update queries using
refetchInterval. It was an amazing UX. Unfortunately, the introduction of the non-configurable "isServer" check broke that because window is undefined in the Raycast execution environment. The remainder of @tanstack/react-query works perfectly except for this one feature.
Anyone know a way around it?11 Replies
flat-fuchsiaOP•3y ago
wee-brown•3y ago
what is
raycast 😅 ?flat-fuchsiaOP•3y ago
Think Alfred, but custom behavior is implemented with React: https://www.raycast.com/
Raycast - Supercharged productivity
Raycast lets you control your tools with a few keystrokes. It's designed to keep you focused.
flat-fuchsiaOP•3y ago
Currently I power a bunch of custom GitHub plugins with @tanstack/react-query.
wee-brown•3y ago
So it doesn't have window, but does it have settimeout ?
flat-fuchsiaOP•3y ago
Yup!
My basic understanding is that it's a custom React renderer that runs in Node. So there's a UI, but no "window" object because it's not the web DOM.
In other words, you never render a
<div />—you only render Raycast components and text nodes, essentially. It's extremely good, and I wish more products built extensions this way.
So in other words, I have a query whose results I use to populate a list of List.Items from the @raycast/api package, which contains all available UI elements that can be rendered.flat-fuchsiaOP•3y ago
So in this example, I use the "Codespaces" extension to list my Codespaces using @tanstack/react-query. There's one Codespace (github/github) and I used to be able to use
refetchInterval to actually reflect state changes in each Codespace—for example I can Cmd+K to bring up a subcommand menu from here and start/stop/delete Codespaces, but the status no longer updates because of the isServer check.flat-fuchsiaOP•3y ago
@tanstack/react-query is so good for building Raycast extensions—it works perfect except for this one tiny detail. Could be fixed relatively easily by a
QueryClient config option, maybe?wee-brown•3y ago
Okay, how do you suggest we proceed? The problem is we don't want to run intervals on the server, where we have the same setup: node but no window. Lots of libs use the window check. Can you somehow define window yourself?
flat-fuchsiaOP•3y ago
I'm worried about defining it globally because of the impact it may have on other dependencies.
Would you consider a PR that added a
QueryClient / useQuery config option?
Like refetchOnServer: true.flat-fuchsiaOP•3y ago
This could also benefit other custom React renderers such as https://github.com/vadimdemedes/ink
GitHub
GitHub - vadimdemedes/ink: 🌈 React for interactive command-line app...
🌈 React for interactive command-line apps. Contribute to vadimdemedes/ink development by creating an account on GitHub.