Skip to content

double API queries when changing route.query [useT3Page.js] #363

@morkpl

Description

@morkpl

Calls to the TYPO3 API are executed twice when the query parameter is changed.

Image

When changing the query by using, for example,
await router.push({ query: { ...route.query, page: String(target) } })

/downloads?page=1 >> to >> /downloads?page=2 - etc...

The first execution occurs when the ‘pageCacheKey’ key changes, which in my case is fullPath
‘/downloads?page=1’

  • the ‘pageCacheKey’ key is relative, which means that changing it automatically executes 'useAsyncData'
// node_modules/@t3headless/nuxt-typo3/dist/runtime/composables/useT3Page.js
const { data, execute: getAsyncPage, error } = useAsyncData(
    useLegacyAsyncDataPageKey ? pageCacheKey.value : pageCacheKey,
    () => {
      console.log('useAsyncData new key:', route.fullPath); // /downloads?page=2
      return getPage(route.fullPath)
    },
    {
      immediate: false
    }
  );

The second execution occurs later during the watcher that tracks route.query and, when it changes, executes ‘useAsyncData’ again manually via ‘getPageData() -> getAsyncPage()’.

// node_modules/@t3headless/nuxt-typo3/dist/runtime/composables/useT3Page.js
  watch(() => route.query, () =>
  {
    console.log('execute useAsyncData > new query', route.fullPath); // /downloads?page=2
    getPageData()
  });

As a result, after changing the query parameter from ‘page=1’ to ‘page=2’,
the API query is executed twice.

Question: What was or is the purpose of watcher on route.query?

Versions:

"nuxt": "4.1.0"
"@t3headless/nuxt-typo3": "2.3.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions