blitz-js / blitz-js/blitz

Can not pass Date values as query inputs

Open
#4,193 2 comments 0 reactions 0 assignees View on GitHub
kind/bug status/triage
Dominant language
TypeScript
Stars
14.1k
Forks
803
PR merge metrics
No merged PRs in 30d

Description

### What is the problem?

I am trying to execute a simple query like:
client:
```
const [users] = useQuery(getUsers, { createdAt: new Date() })
```
but the query run infinitily
I tried
```
const input= useRef({ createdAt: new Date() }).current
const [users,{refetch}] = useQuery(getUsers, input)
```
Same result!
I tried:
```
const input={ createdAt: new Date() }
const Users = () => {
const [users,{refetch}] = useQuery(getUsers, input)
return (
<>
{users?.map((user, i) => (


{user.name}

))}

)
}
```
and that works

It should works at least in the second scenario without problems

### Paste all your error logs here:

image

### Paste all relevant code snippets here:

client
```
import { Suspense, useRef, useState } from "react"
import Layout from "src/core/layouts/Layout"
import { useQuery } from "@blitzjs/rpc"
import { BlitzPage } from "@blitzjs/next"
import getUsers from "../users/queries/getUsers"

const input={ createdAt: new Date() }
const Users = () => {
const input= useRef({ createdAt: new Date() }).current
const [users,{refetch}] = useQuery(getUsers, input)
return (
<>
refetch()}>Refetch
{users?.map((user, i) => (


{user.name}

))}

)
}

const Home: BlitzPage = () => {
return (





)
}

export default Home
```
server:
```
import { resolver } from "@blitzjs/rpc"
import db from "db"
import { z } from "zod"

const GetUsers = z.object({
createdAt: z.date()
})

export default resolver.pipe(
resolver.zod(GetUsers),
async ({ createdAt }) => {
return await db.user.findMany({ where: { createdAt: { gte: createdAt } } })
}
)

### What are detailed steps to reproduce this?

```
git clone https://github.com/cesarve77/date-error-blitz.git
cd date-error-blitz
npm i
blitz dev
```

### Run `blitz -v` and paste the output here:

```
Blitz version: 2.0.0-beta.31 (global)
Blitz version: 2.0.0-beta.31 (local)
macOS Ventura | darwin-arm64 | Node: v18.15.0

Package manager: pnpm

System:
OS: macOS 13.4.1
CPU: (8) arm64 Apple M1
Memory: 122.16 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.15.0/bin/yarn
npm: 9.5.0 - ~/.nvm/versions/node/v18.15.0/bin/npm
npmPackages:
@blitzjs/auth: 2.0.0-beta.31 => 2.0.0-beta.31
@blitzjs/next: 2.0.0-beta.31 => 2.0.0-beta.31
@blitzjs/rpc: 2.0.0-beta.31 => 2.0.0-beta.31
@prisma/client: 4.6.1 => 4.6.1
blitz: 2.0.0-beta.31 => 2.0.0-beta.31
next: 13.4.5 => 13.4.5
prisma: 4.6.1 => 4.6.1
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
typescript: ^4.8.4 => 4.8.4 ```

### Please include below any other applicable logs and screenshots that show your problem:

_No response_

Contributor guide

Open the contributing guide

Research direction

Run the linked date-error-blitz reproduction with the reported Blitz, React, Next.js, and Prisma versions. Trace the useQuery input handling alongside resolver.zod and the createdAt query, comparing inline, useRef, and module-level inputs. Done means Date-valued inputs no longer trigger an infinite query loop and the documented scenarios complete normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, react, typescript
Domain
api, backend, full-stack
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.