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

luismabenitez's avatar

preserveState not working properly

On my app with Vue3 have this watcher:

watch: {
    filter: {
        handler: _.throttle(function () {
            this.$inertia.get('/contacts', { filter: this.filter }, {
                preserveState: true,
                replace: true,
                preserveScroll: true,
            });
        }, 400),
        deep: true
    }
},

It keeps the v-model in the inputs but it loses the focus. The filtering works and have no errors in console, but after one key pressed, the page do the request and loses the focus on the input.

0 likes
3 replies
jbloomstrom's avatar

I think debounce would be more appropriate for your use case.

In summary, throttle limits the execution rate of a function to once every X milliseconds, while debounce delays the function execution until an event has stopped occurring for X milliseconds.

watch: {
    filter: {
        handler: _.debounce(function () {
            this.$inertia.get('/contacts', { filter: this.filter }, {
                preserveState: true,
                replace: true,
                preserveScroll: true,
            });
        }, 400),
        deep: true
    }
},

Edit: But that doesn't answer why it's not preserving state. Can you share the entire component?

Please or to participate in this conversation.