dify - ✅(Solved) Fix After publishing, the first time the agent conversation page references a document from the knowledge base, the download link does not appear. The download link will only appear after refreshing the page [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langgenius/dify#35484Fetched 2026-04-23 07:45:32
View on GitHub
Comments
1
Participants
1
Timeline
3
Reactions
1
Participants
Timeline (top)
commented ×1cross-referenced ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #35500: Fix/35484 kb citation download first load

Description (problem / solution / changelog)

Summary

Fixes an issue where the knowledge base document download control in the citation popover did not appear the first time a published agent answered with citations; it showed correctly after a full page refresh (#35484).

Root cause

  • The download button only considered sources[0] for dataset_id. For merged multi-segment citations, streaming message_end metadata can include segments where the first hit has no dataset_id and a later hit does; history/API responses are often complete, so refresh masked the bug.
  • Citation chip layout ran once on mount; when resources arrived or the container was not ready, visible chips could be wrong until remount (e.g. refresh).

Changes

  • citation/popup.tsx: Resolve dataset_id / document_id via getPrimaryFileSource() (prefer a segment with both ids, else first with dataset_id).
  • citation/index.tsx: Use useLayoutEffect with [resources, containerClassName], null-safe container and ref access, and fallbacks when the container is missing.
  • chat/hooks.ts: If message_end includes both annotation_reply and retriever_resources, still set citation before returning.
  • Tests: New case in popup.spec.tsx — first source without dataset_id, second with — download button still shown.

How to test

  1. Self-hosted, workflow agent with a KB and retrieve source enabled; publish and open a new chat.
  2. Ask a question that returns a citation; open the cite popover — Download should appear without refreshing.
  3. (Optional) Run: pnpm vitest run app/components/base/chat/chat/citation/__tests__/popup.spec.tsx Closes #35484

Changed files

  • api/core/rag/datasource/retrieval_service.py (modified, +33/-3)
  • api/tests/unit_tests/core/rag/datasource/test_datasource_retrieval.py (modified, +9/-0)
  • web/app/components/base/chat/chat/citation/__tests__/popup.spec.tsx (modified, +19/-0)
  • web/app/components/base/chat/chat/citation/index.tsx (modified, +21/-8)
  • web/app/components/base/chat/chat/citation/popup.tsx (modified, +19/-3)
  • web/app/components/base/chat/chat/hooks.ts (modified, +4/-0)
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.13.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Build a knowledge base question-answering intelligent agent using workflow and publish it
  2. Initiate a Q&A session
  3. Clicking on the referenced document in the answer section does not display a download link
  4. Refresh the page to display the download link

✔️ Expected Behavior

if it is a bug fix it

❌ Actual Behavior

No response

extent analysis

TL;DR

The issue with the download link not displaying in the answer section of a Q&A session in a self-hosted Dify instance may be resolved by refreshing the page.

Guidance

  • Verify that the referenced document is correctly configured and accessible within the knowledge base.
  • Check the workflow and publishing settings to ensure that the document is properly linked and permissions are set correctly.
  • Investigate potential caching issues that might be preventing the download link from displaying initially.
  • Consider reviewing the browser console for any JavaScript errors that could be related to the issue.

Example

No code snippet is provided as the issue does not specify any specific code-related details.

Notes

The provided information suggests a potential issue with how the download link is rendered or updated in the UI, possibly related to caching or asynchronous loading. However, without more technical details, it's challenging to provide a definitive fix.

Recommendation

Apply workaround: Refresh the page to display the download link, as this has been observed to temporarily resolve the issue. This recommendation is based on the steps to reproduce and the actual behavior described, indicating that a simple page refresh can make the download link appear, suggesting a potential issue with initial page load or caching.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

dify - ✅(Solved) Fix After publishing, the first time the agent conversation page references a document from the knowledge base, the download link does not appear. The download link will only appear after refreshing the page [1 pull requests, 1 comments, 1 participants]