Skip to content

Conversation

maoguy
Copy link
Contributor

@maoguy maoguy commented Aug 8, 2025

Before Widget unmounted and clear the method of window.clearChainlitCopilotThredId, call the window.clearChainlitCopilotThreadId?.();

which can fix the bug : #2384

Before Widget unmounted and clear the method of window.clearChainlitCopilotThredId, call the window.clearChainlitCopilotThreadId?.();
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Aug 8, 2025
@xjose97x
Copy link
Contributor

xjose97x commented Aug 8, 2025

@maoguy I don't quite understand this issue. Could you please provide more details?

@maoguy
Copy link
Contributor Author

maoguy commented Aug 11, 2025

@maoguy I don't quite understand this issue. Could you please provide more details?

Reproduce

To Reproduce,you can try to do that 👇:
1.【Backend】Set the commands and setting in just like👇【docs ref 👉 https://docs.chainlit.io/concepts/command#command】
image
image
2.【Frontend】Use the method of window.mountChainlitWidget to mount the widget firstly,so we can see the corrected view 👇
image
3.【Frontend】Use the method of window.unmountChainlitWidget() to unmount the widget,and then use the method of window.mountChainlitWidget to remount the widget again.At this point, the error occurs👇we can not see the commands menu.
image

Possible cause

I believe the root cause is that after the plug-in was uninstalled and remounted, no new session was initiated.Therefore the websocket of backend don`t know when should push the new config again.👇
image

@xjose97x
Copy link
Contributor

@maoguy Oh, understood. I'll take a look at this case during this week.

@asvishnyakov asvishnyakov changed the title Update widget.tsx fix: command menu disappears after unmounting and mounting copilot widget back Aug 11, 2025
@hayescode
Copy link
Contributor

@maoguy does #2393 fix this for you?

@maoguy
Copy link
Contributor Author

maoguy commented Aug 13, 2025

@maoguy does #2393 fix this for you?

I try to pull the pr to test,the new commands UI is very nice!👍
But Unfortunately, it still doesn’t solve my problem.😂

95b690dce199296ace3b911adf628f39.mp4

@xjose97x
Copy link
Contributor

The proposed fix in this PR changes the threadId on every remount. I don't believe this is the right fix.
I'm currently doing some research on this and will provide a PR once I find the root cause.

@maoguy
Copy link
Contributor Author

maoguy commented Aug 14, 2025

The proposed fix in this PR changes the threadId on every remount. I don't believe this is the right fix. I'm currently doing some research on this and will provide a PR once I find the root cause.

I believe the plugin should expose configurable lifecycle hooks—such as a "afterMounted" that fires once the plugin is successfully mounted,or a "beforeUnmounted" hook that is invoked right before the plugin is torn down.

With either of these two lifecycle hooks available, we could call window.clearChainlitCopilotThreadId inside mountedCallback (to start a fresh session after remount) or inside beforeUnmounted (to clean up the current session before the plugin is torn down), ensuring the thread ID is properly reset.

@maoguy
Copy link
Contributor Author

maoguy commented Aug 14, 2025

The proposed fix in this PR changes the threadId on every remount. I don't believe this is the right fix. I'm currently doing some research on this and will provide a PR once I find the root cause.

I think the root cause is that after the browser-side plugin is unmounted and remounted, the server is unaware of the change, so the WebSocket-based set_commands event is never pushed.

@xjose97x
Copy link
Contributor

The proposed fix in this PR changes the threadId on every remount. I don't believe this is the right fix. I'm currently doing some research on this and will provide a PR once I find the root cause.

I think the root cause is that after the browser-side plugin is unmounted and remounted, the server is unaware of the change, so the WebSocket-based set_commands event is never pushed.

I believe the correct fix would be to store the set_commands event in the persistence layer—likely by converting it into a Step.
That way, when the widget is remounted and the message history and steps are reloaded, the commands will be restored automatically.

@maoguy
Copy link
Contributor Author

maoguy commented Aug 15, 2025

The proposed fix in this PR changes the threadId on every remount. I don't believe this is the right fix. I'm currently doing some research on this and will provide a PR once I find the root cause.

I think the root cause is that after the browser-side plugin is unmounted and remounted, the server is unaware of the change, so the WebSocket-based set_commands event is never pushed.

I believe the correct fix would be to store the set_commands event in the persistence layer—likely by converting it into a Step. That way, when the widget is remounted and the message history and steps are reloaded, the commands will be restored automatically.

The proposed fix in this PR changes the threadId on every remount. I don't believe this is the right fix. I'm currently doing some research on this and will provide a PR once I find the root cause.

I think the root cause is that after the browser-side plugin is unmounted and remounted, the server is unaware of the change, so the WebSocket-based set_commands event is never pushed.

I believe the correct fix would be to store the set_commands event in the persistence layer—likely by converting it into a Step. That way, when the widget is remounted and the message history and steps are reloaded, the commands will be restored automatically.

Could this approach be interpreted as modifying the react-client layer to persist a copy of the commandsState—a global state managed by Recoil—into localStorage?☺

@maoguy maoguy closed this by deleting the head repository Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants