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

UseSearch not updating #2798

Open
master8848 opened this issue Nov 18, 2024 · 2 comments
Open

UseSearch not updating #2798

master8848 opened this issue Nov 18, 2024 · 2 comments

Comments

@master8848
Copy link

Which project does this relate to?

Router

Describe the bug

I have a application where generic components are managing search and filter states also search and filter states are using navigation but use search is not updating.

navigate is changing url but its not rerunning useMemo when console log without use effect Appliction is not rerunning on change of searchParams

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-5lj1t6?file=src%2Froutes%2Findex.tsx,src%2Froutes%2F__root.tsx&preset=node

Steps to Reproduce the Bug or Issue

	"@tanstack/router-zod-adapter": "^1.58.9",
	"@tanstack/react-router": "^1.82.0",

my on Filter/search change after debounce for search is something like

const onFilterChange = useCallback(
(v: T): void | Promise => {
navigate({
to: '.',
search: (c) => {
console.log('FilterBar.tsx:122', c)
const newValue = v

				const retunning = c
				if (!retunning.q) retunning.q = {}

				Object.assign(retunning.q, newValue, {
					page: c.q?.page ?? 1,
					search: search || undefined,
				})
				Object.assign(retunning, newValue, {
					page: c.q?.page ?? 1,
					search: search || undefined,
				})

				return retunning
			},
		})
	},
	[navigate,  search],
)

for this console log "FilterBar.tsx:122" all latest values are available while console log in route page is not updating
"""
const params = Route.useSearch()
console.log(params)
"""

Defination of searchValidation is done like
"""
export const ZodListQuerySchemaExtend = {
page: fallback(number().optional(), 1).default(1),
search: fallback(string().optional(), ''),
order_by: fallback(string().optional(), ''),

[QUERY_STRINGS.start_date]: fallback(DATE_ZOD_VALIDATOR, undefined),
[QUERY_STRINGS.end_date]: fallback(DATE_ZOD_VALIDATOR, undefined),

}
const searchSchema = z.object({
q: fallback(z.object(ZodListQuerySchemaExtend), { page: 1 }),
})
export const Route = createFileRoute('')({
component: Component,
validateSearch: zodSearchValidator(searchSchema),
})
"""

Expected behavior

console log in Component should be updated when url changes

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

@master8848
Copy link
Author

master8848 commented Nov 20, 2024

I checked recreation of nested state with different object works but could that be mentioned on use search params docs for new object needs to be created ,as react state normally re run if first level object is recreated into new object so for garbage collection saving our product uses reassign to same object reference on nested object but for this case it goes differently than react state

Also I am aware of use memo and use callback not trigging on nested items if reference of nested item is not changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants