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

Fix useRouteQuery reactivity #345

Merged
merged 2 commits into from
Nov 15, 2023
Merged

Fix useRouteQuery reactivity #345

merged 2 commits into from
Nov 15, 2023

Conversation

pleek91
Copy link
Collaborator

@pleek91 pleek91 commented Nov 15, 2023

Description

useRouteQuery works by creating an array of operations to apply to the query and then updating the query in batches. But when the operations were flushed to the actual route the operations were being cleared before updating the route. This resulted in individual query params flipping from the new value to the old value and then back to the new value.

Reproduction

<template>
  <button type="button" @click="testing">click me</button>
</template>

<script setup lang="ts">
  const tab = useRouteQueryParam('tab')

  watch(tab, () => {
    console.log('tab changed', tab.value)
  })

  function testing(): void {
    tab.value = randomId()
  }
</script>

Result

tab changed bd123e4b-75e2-41bd-bd20-39c53a246fe7. ---- (new)
tab changed 93b2ba30-2797-4c78-ab38-7d987913bc05 ---- (old)
tab changed bd123e4b-75e2-41bd-bd20-39c53a246fe7 ---- (new)

Expected

tab changed bd123e4b-75e2-41bd-bd20-39c53a246fe7. ---- (new)

Fix

Waiting to clear the operations from the queue until after they have been applied to the route fixes the issue.

Thank you @collincchoy for the reproduction and debugging you did on #332 which was a bandaid fix that we ultimately reverted because it caused other issues.

@pleek91 pleek91 requested a review from a team as a code owner November 15, 2023 18:26
Copy link
Contributor

@znicholasbrown znicholasbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subtle

@pleek91 pleek91 merged commit b2bc614 into main Nov 15, 2023
3 checks passed
@pleek91 pleek91 deleted the query-param-reactivity-fix branch November 15, 2023 18:34
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

Successfully merging this pull request may close these issues.

2 participants