show log in agent page and then go back to previous page, choose any other agent or chat app, the previous log still show and throw error #14119

Closed
opened 2026-02-21 19:15:38 -05:00 by yindo · 5 comments
Owner

Originally created by @Covfefeable on GitHub (May 22, 2025).

Self Checks

  • 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 (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.4.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

click log operation after an answer, and modal shows
Image

back to previous page, or click "studio" directly

choose another agent or chat app, the modal still there

Image

✔️ Expected Behavior

the modal should be closed after leave the current page

Actual Behavior

the modal doesn't close

Originally created by @Covfefeable on GitHub (May 22, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.4.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce click log operation after an answer, and modal shows ![Image](https://github.com/user-attachments/assets/7b79eac6-8c4e-4ef7-9bac-e2be7f472961) back to previous page, or click "studio" directly choose another agent or chat app, the modal still there ![Image](https://github.com/user-attachments/assets/f7c2c2b5-787c-45d4-8d67-546e74008c85) ### ✔️ Expected Behavior the modal should be closed after leave the current page ### ❌ Actual Behavior the modal doesn't close
yindo added the 🐞 bug label 2026-02-21 19:15:38 -05:00
yindo closed this issue 2026-02-21 19:15:38 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (May 22, 2025):

Based on your description and review of the codebase, the issue occurs because the modal (such as the Agent Log modal) does not automatically close when you navigate away from the agent page or switch to another agent/chat app. The modal remains visible and can throw errors, which is not the expected behavior.

From the implementation, modal visibility in Dify is managed via state in the context (see modal-context.tsx), and modals like AgentLogModal rely on user actions (such as clicking outside or the close icon) to trigger their onCancel handler and close themselves. However, there is no automatic cleanup or state reset tied to navigation events or route changes, which would explain why the modal persists when you leave the page or switch agents. This is likely a gap in event handling or state management related to navigation/routing logic in the app.

A typical solution would be to listen for route changes (using your router's event hooks, such as useEffect with router events in Next.js or React Router) and programmatically trigger the modal's close handler or reset its state when navigation occurs. This ensures that any open modal is closed as soon as the user leaves the relevant context.

There are currently no existing issues or discussions in the repository that specifically address this modal persistence problem when navigating away from the agent page.

Summary of the cause:

  • Modal state is not reset on navigation, so the modal remains open even after leaving the page.
  • The current implementation only closes the modal on direct user interaction, not on route changes.

Guidance for resolution:

  • Implement a listener for route changes in the component or context that manages modal state.
  • On route change, call the appropriate close/reset function for any open modal.

If you need more specific guidance on where to add this logic in your codebase, let me know which router or framework you are using, and I can provide a code example.

To continue talking to Dosu, mention @dosu-bot.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (May 22, 2025): <!-- Answer --> Based on your description and review of the codebase, the issue occurs because the modal (such as the Agent Log modal) does not automatically close when you navigate away from the agent page or switch to another agent/chat app. The modal remains visible and can throw errors, which is not the expected behavior. From the implementation, modal visibility in Dify is managed via state in the context (see [`modal-context.tsx`](https://github.com/langgenius/dify/blob/main/web/context/modal-context.tsx)), and modals like `AgentLogModal` rely on user actions (such as clicking outside or the close icon) to trigger their `onCancel` handler and close themselves. However, there is no automatic cleanup or state reset tied to navigation events or route changes, which would explain why the modal persists when you leave the page or switch agents. This is likely a gap in event handling or state management related to navigation/routing logic in the app. A typical solution would be to listen for route changes (using your router's event hooks, such as `useEffect` with router events in Next.js or React Router) and programmatically trigger the modal's close handler or reset its state when navigation occurs. This ensures that any open modal is closed as soon as the user leaves the relevant context. There are currently no existing issues or discussions in the repository that specifically address this modal persistence problem when navigating away from the agent page. **Summary of the cause:** - Modal state is not reset on navigation, so the modal remains open even after leaving the page. - The current implementation only closes the modal on direct user interaction, not on route changes. **Guidance for resolution:** - Implement a listener for route changes in the component or context that manages modal state. - On route change, call the appropriate close/reset function for any open modal. If you need more specific guidance on where to add this logic in your codebase, let me know which router or framework you are using, and I can provide a code example. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://go.dosu.dev/dosubot), mention @dosu-bot.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/1f7ebd04-1f47-451c-9009-40012923a2fd?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/1f7ebd04-1f47-451c-9009-40012923a2fd?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/1f7ebd04-1f47-451c-9009-40012923a2fd?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/1f7ebd04-1f47-451c-9009-40012923a2fd?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1f7ebd04-1f47-451c-9009-40012923a2fd?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/1f7ebd04-1f47-451c-9009-40012923a2fd?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1f7ebd04-1f47-451c-9009-40012923a2fd?feedback_type=other)</sup>
Author
Owner

@Covfefeable commented on GitHub (May 22, 2025):

It seems that useClickAway in app/components/base/agent-log-modal/index.tsx does not take effect when going back or clicking "studio"

Image

@Covfefeable commented on GitHub (May 22, 2025): It seems that ```useClickAway``` in ```app/components/base/agent-log-modal/index.tsx``` does not take effect when going back or clicking "studio" ![Image](https://github.com/user-attachments/assets/6403e038-61f0-483f-9de5-78ed9ea67977)
Author
Owner

@HyaCiovo commented on GitHub (May 22, 2025):

It seems that useClickAway in app/components/base/agent-log-modal/index.tsx does not take effect when going back or clicking "studio"

...

I think we should clear all modals and set currentItem to undefined when the modals' parent component will unmount

Image

Image

@HyaCiovo commented on GitHub (May 22, 2025): > It seems that `useClickAway` in `app/components/base/agent-log-modal/index.tsx` does not take effect when going back or clicking "studio" > > ... I think we should clear all modals and set `currentItem` to `undefined` when the modals' parent component will unmount ![Image](https://github.com/user-attachments/assets/013a1b34-e2ab-464f-922e-fb05474db42b) ![Image](https://github.com/user-attachments/assets/5eb509ab-b9c0-427e-9db6-48446ea210c8)
Author
Owner

@HyaCiovo commented on GitHub (May 26, 2025):

It seems that useClickAway in app/components/base/agent-log-modal/index.tsx does not take effect when going back or clicking "studio"
...

I think we should clear all modals and set currentItem to undefined when the modals' parent component will unmount

Woops, I found that in StrictMode, the cleanup function of useEffect(fn, []) executes immediately once, and the same happens in useUnmount. I cannot modify the modal's state in the cleanup function, as it causes the modal to fail to display in the development environment.

@HyaCiovo commented on GitHub (May 26, 2025): > > It seems that `useClickAway` in `app/components/base/agent-log-modal/index.tsx` does not take effect when going back or clicking "studio" > > ... > > I think we should clear all modals and set `currentItem` to `undefined` when the modals' parent component will unmount Woops, I found that in `StrictMode`, the `cleanup` function of `useEffect(fn, [])` executes immediately once, and the same happens in `useUnmount`. I cannot modify the modal's state in the `cleanup` function, as it causes the modal to fail to display in the development environment.
Author
Owner

@dosubot[bot] commented on GitHub (Aug 27, 2025):

Hi, @Covfefeable. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported a bug in version 1.4.0 (self-hosted Docker) where the agent log modal stays open and causes errors after navigation or switching agents.
  • The root cause is that modal state isn't reset on route changes, only on direct user interaction, so the modal persists improperly.
  • You noted that the useClickAway hook doesn't close the modal on navigation.
  • A maintainer suggested clearing modals and resetting state on parent component unmount, but React StrictMode causes cleanup functions to run prematurely, complicating the fix.
  • Further work is needed to handle modal state cleanup correctly on navigation without breaking development mode behavior.

What's Next:

  • Please let me know if this issue is still relevant with the latest version of Dify by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 27, 2025): Hi, @Covfefeable. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported a bug in version 1.4.0 (self-hosted Docker) where the agent log modal stays open and causes errors after navigation or switching agents. - The root cause is that modal state isn't reset on route changes, only on direct user interaction, so the modal persists improperly. - You noted that the `useClickAway` hook doesn't close the modal on navigation. - A maintainer suggested clearing modals and resetting state on parent component unmount, but React StrictMode causes cleanup functions to run prematurely, complicating the fix. - Further work is needed to handle modal state cleanup correctly on navigation without breaking development mode behavior. **What's Next:** - Please let me know if this issue is still relevant with the latest version of Dify by commenting here to keep the discussion open. - Otherwise, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#14119