Skip to content

Migrate entities and attribute values stores - #2049

Merged
axelboc merged 1 commit into
react-queryfrom
react-query-cont-1
Sep 10, 2026
Merged

axelboc merged 1 commit into
react-queryfrom
react-query-cont-1

Conversation

@axelboc

@axelboc axelboc commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

For the simplest example usage of the new queries.entity(path), see useEntity and useDatasets in packages/app/src/hooks.ts (useEntity is called in the explorer and the metadata viewer; useDatasets is used only in Hibou). Those are already both hooks and they both called entitiesStore.get() directly without any conditions, so migrating to useSuspenseQuery(ies) was trivial.

For the simplest example usage of the new queries.attrValues(entity), see the metadata viewer's AttributesInfo component — it called attrValuesStore.get() directly and unconditionally, so trivial also.


The more challenging cases are when store.get() is called conditionally, sometimes deep inside a stack of synchronous functions...

Let's take useNxData, which is used by all the NeXus vis containers:

  1. it calls findSignalDataset
  2. findSignalDataset checks if the NXdata group has a "signal" attribute
  3. If it does (and only if), then it asks the provider for the value of the "signal" attribute with attrValuesStore.get(group)["signal"] (via getAttributeValue).

And that's just one of the many attribute values that useNxData requests, conditionally or not, but always a few functions deep.

At this point it's good to remind ourselves why we request attribute values conditionally: we want to avoid making unnecessary requests to remote providers like h5grove. So removing the conditions and turning every function into a custom hook so we can call useSuspenseQuery(queries.attrValues()) deep into the call stack is not an option. For the same reason, we also can't retrieve all the attribute values in useNxData and pass them down.

The only option is to call useSuspenseQuery from useNxData. But then how do we replace the calls to attrValuesStore.get() within nested functions like getAttributeValue?

Fortunately, Tanstack Query provides a way to invoke a query without useSuspenseQuery: it's called queryClient.query() (very recently renamed from fetchQuery).

The problem is that it's async so it means that every function has to be made async (async keyword, Promise return type, and await at call site). This is what most of the diff is about.

The other similar case to useNxData is the resolvePath function that is called from the Visualizer to find the supported visualization for a given entity.


Finally, there are the few intermediate cases where it's not quite clear whether a new dedicated query like "nxData" or "resolution" is needed or not, and whether efforts should be put into trying not to trigger the query when possible (with useSuspenseQueries and an empty queries array).


Hopefully, this gives a good overview. For the remaining explanations, I'll comment inline.

@axelboc
axelboc force-pushed the react-query-cont-1 branch 2 times, most recently from 62c9697 to 5489879 Compare September 4, 2026 09:22
Comment thread packages/app/src/explorer/NxBadge.tsx
Comment thread packages/app/src/providers/DataProvider.tsx
Comment thread packages/app/src/vis-packs/core/heatmap/HeatmapVisContainer.tsx
Comment thread packages/app/src/vis-packs/netcdf/hooks.ts
Comment thread packages/app/src/vis-packs/nexus/hooks.ts
Comment thread packages/app/src/vis-packs/nexus/hooks.ts
Comment thread packages/app/src/vis-packs/ValueLoader.tsx
Comment thread packages/app/src/visualizer/queries.ts
Comment thread packages/app/src/hooks.ts
Comment thread packages/app/src/providers/DataProvider.tsx
@axelboc
axelboc requested a review from loichuder September 4, 2026 11:42

@loichuder loichuder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool !

We can discuss the ignoreValue thingy later if you wish.

Comment thread packages/app/src/explorer/NxBadge.tsx
Comment thread packages/app/src/providers/DataProvider.tsx
Comment thread packages/app/src/vis-packs/core/heatmap/HeatmapVisContainer.tsx
Comment thread packages/app/src/vis-packs/core/heatmap/HeatmapVisContainer.tsx
Comment thread packages/app/src/vis-packs/netcdf/hooks.ts Outdated
@axelboc
axelboc merged commit 77ed499 into main Sep 10, 2026
13 checks passed
@axelboc
axelboc deleted the react-query-cont-1 branch September 10, 2026 08:32
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