fix(workflow): re-fetch dataset details when workflow nodes change
DatasetsDetailProvider fetches dataset metadata only on mount, leaving store stale when workflow graph changes
web/app/components/workflow/datasets-detail-store/provider.tsx lines 34-46 — the effect that fetches dataset details for knowledge-retrieval nodes has an empty dependency array, but reads the nodes prop. As a result, the fetch only happens when the provider first mounts. Any subsequent change to the workflow graph leaves the dataset-detail store in its initial state, even though the graph on screen has been replaced.
Trigger scenarios
- Loading a different saved workflow while the workflow editor stays mounted.
- Real-time collaboration: another user adds, removes, or changes the dataset IDs of a knowledge-retrieval node.
- Undo / redo of node additions or deletions.
- Adding or removing a knowledge-retrieval node after the initial mount.
- Snippet insertion that introduces or rewires nodes.
In each case, consumers of the store (dataset pickers, dataset-name previews, validation messages that need the dataset title) display either the original dataset list, missing entries, or datasets that no longer exist on the workflow.
Expected
The dataset-detail store reflects the current set of datasets referenced by any knowledge-retrieval node in the live workflow graph.
Actual
The store is populated only once, on initial mount. Subsequent workflow-graph changes are not reflected.
Suggested fix
Add nodes (and updateDatasetsDetail for completeness, even though it is already memoized with [] deps) to the effect's dependency array:
useEffect(() => {
...
updateDatasetsDetail(allDatasetIds)
}, [nodes, updateDatasetsDetail])
Hi @AlexMultiAgent, thanks for opening this issue.
Why this is being closed
The stale-store analysis lists possible triggers, but the report does not identify the tested version or commit, deployment, or which scenario was reproduced with observable results. The bug report template asks for version, deployment and reproduction context. This closure does not establish whether the observation is correct.
Next steps
Please add the exact version or commit and deployment, and provide a minimal workflow or source-test reproduction for one trigger, including observed and expected dataset details.
Once the context is available, a maintainer can reassess the report.
Thanks for clarifying what was missing. Here is a minimal source-test reproduction for one trigger: replacing the dataset IDs of a knowledge-retrieval node while the provider stays mounted.
- Dify baseline:
3ec3e61bcbd03e7dcc678e3ac7d047a28c7a222e, the base of #45870. - Environment: local frontend source checkout, Node 24.22.1 and pnpm 12.16.1 (as declared by that checkout). The test mocks the dataset API, so no Docker deployment, backend, or existing datasets are needed.
From the repository root in a clean checkout of that baseline, apply only the test change from #45870. Leave provider.tsx unchanged, so the test still exercises the affected code:
git switch --detach 3ec3e61bcbd03e7dcc678e3ac7d047a28c7a222e
spec=web/app/components/workflow/datasets-detail-store/__tests__/provider.spec.tsx
gh pr diff 45870 -R langgenius/dify | git apply --include="$spec" -
pnpm install --frozen-lockfile
pnpm --dir web exec vp test run --project unit --maxWorkers=2 "${spec#web/}" -t 'should refetch when a knowledge retrieval node changes the referenced dataset ids'
The test first renders one retrieval node with dataset_ids: ['dataset-1']. It mocks the first response and waits for the initial fetch. It then rerenders the same provider with dataset_ids: ['dataset-2'], without unmounting it, and supplies a mock response for the second dataset.
- Affected behavior: the effect at the pinned baseline has
[]dependencies. Only the initial fetch fordataset-1occurs, so the consumer does not showdataset-2: Dataset dataset-2. The first failing assertion should be the fetch count (expected 2, actual 1). - Expected: a second fetch with
params: { page: 1, ids: ['dataset-2'] }, followed by the consumer displayingdataset-2: Dataset dataset-2.
I checked that the test-only patch applies to the pinned baseline and confirmed the empty effect dependencies in that source. The outcomes above describe what to check when running the reproduction; I did not rerun Vitest for this comment. This repro covers the dataset-ID replacement trigger specifically.