Skip to content

Improve data fetching tool integration with the HTML stream? #1689

Open
@brillout

Description

@brillout

By using Vike extensions, such as vike-react-query and soon vike-react-telefunc, you can fetch data on a component-level (thus on a layout-level as well).

Since TanStack Query is caching independently the URL, it just works. That said, there is potential for improving the caching behavior.

Note

Data fetching Vike Extensions already have a cache (they always need to), so it's just a matter of configuring the cache.

Technical details.

Approach A

vike-{react,vue,solid} provides a new component hook useDataCacheKey() that returns a key composed of:

  • The URL, but without the pathnames of all the nested layouts that the component doesn't belong to.
  • The timestamp when Vike changed the URL.

Vike extensions can then use the key to cache data. In other words, the behavior is exactly as the website visitor expects: data is re-fetched only when navigating the relevant parts of the UI.

Approach B

Alternatively, vike-{react,vue,solid} wraps the nested layouts in a stateful wrapper component (e.g. using React's useState()). Upon navigation, the state of the appropriate wrapper components is updated to trigger a re-render of nested layouts (the page and outer layout aren't re-rendered). But, so far, I think Approach A is superior. (For example, I don't see how Approach B can support the use case when the user clicks on the active link merely to refresh the page.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions