Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

undeportedmexican's avatar

Query String won't clear when empty data object

I've done this on the past and I don't remember ever struggling with this, but maybe I did it different.

I have my regular index controller, returning an inertia view, everything wotks perfect.

My issue comes when I add filters. I'm using a watcher on a reactive filters object to trigger a page reload, where my controller will catch it and filter the data accordingly.

Everything works fine, except when I clear the filter ( a text input to make a name search ). When I clear that input, the query string remains with the last state it had, it never clears. Even if I send an empty data object in the Inertia router visit options.

Is this a bug? Am i doing something wrong?

Here's the watcher I'm using:

const filters = reactive(props.queryFilters);

watch(
    filters,
    debounce(() => {

        let options = {};

        let pickedFilters = pickBy(filters);

        if (Object.keys(pickedFilters).length > 0){
            options.data = pickedFilters;
        }

        router.reload(options);
    }, 200)
);
0 likes
3 replies
jlrdw's avatar

Pass a cleared query string as well.

undeportedmexican's avatar

@jlrdw

Do you mean something like this?

data:{
	searchString: '',
	status: ''
}

If that's what you mean, it does work, it just feels 'dirty'. I was wondering if this would be a bug, or if it would be by design.

undeportedmexican's avatar

So, apparently if I do reload.get(...) it works as expected. I guess the reload option doesn't really messes with the query string that much.

Please or to participate in this conversation.