mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 18:27:19 +08:00
fix: prioritize URL conversation_id over localStorage in embedded chatbot (#35519)
Co-authored-by: KimNamWoo <treekim@KimNamWoos-Mac-mini.local> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3e4849d765
commit
5a7a955210
@ -532,6 +532,7 @@ describe('useEmbeddedChatbot', () => {
|
||||
})
|
||||
|
||||
it('handleChangeConversation updates current conversation and refetches chat list', async () => {
|
||||
mockStoreState.embeddedConversationId = null
|
||||
const { result } = await renderWithClient(() => useEmbeddedChatbot(AppSourceType.webApp))
|
||||
|
||||
act(() => {
|
||||
@ -548,6 +549,39 @@ describe('useEmbeddedChatbot', () => {
|
||||
expect(result.current.clearChatList).toBe(false)
|
||||
})
|
||||
|
||||
// Scenario: URL-provided conversation_id should take precedence over localStorage value.
|
||||
it('should prioritize URL conversation_id over localStorage', async () => {
|
||||
localStorage.setItem(CONVERSATION_ID_INFO, JSON.stringify({
|
||||
'app-1': { 'embedded-user-1': 'stored-conv-id' },
|
||||
}))
|
||||
mockStoreState.embeddedConversationId = 'url-conv-id'
|
||||
mockGetProcessedSystemVariablesFromUrlParams.mockResolvedValue({
|
||||
user_id: 'embedded-user-1',
|
||||
conversation_id: 'url-conv-id',
|
||||
})
|
||||
|
||||
const { result } = await renderWithClient(() => useEmbeddedChatbot(AppSourceType.webApp))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.currentConversationId).toBe('url-conv-id')
|
||||
})
|
||||
})
|
||||
|
||||
// Scenario: When no URL conversation_id is provided, fall back to localStorage.
|
||||
it('should fall back to localStorage when no URL conversation_id is provided', async () => {
|
||||
localStorage.setItem(CONVERSATION_ID_INFO, JSON.stringify({
|
||||
'app-1': { DEFAULT: 'stored-conv-id' },
|
||||
}))
|
||||
mockStoreState.embeddedConversationId = null
|
||||
mockStoreState.embeddedUserId = null
|
||||
|
||||
const { result } = await renderWithClient(() => useEmbeddedChatbot(AppSourceType.webApp))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.currentConversationId).toBe('stored-conv-id')
|
||||
})
|
||||
})
|
||||
|
||||
it('handleFeedback invokes updateFeedback service successfully', async () => {
|
||||
const { updateFeedback } = await import('@/service/share')
|
||||
const { result } = await renderWithClient(() => useEmbeddedChatbot(AppSourceType.webApp))
|
||||
|
||||
@ -113,7 +113,7 @@ export const useEmbeddedChatbot = (appSourceType: AppSourceType, tryAppId?: stri
|
||||
})
|
||||
}, [setConversationIdInfo])
|
||||
const allowResetChat = !conversationId
|
||||
const currentConversationId = useMemo(() => conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || conversationId || '', [appId, conversationIdInfo, userId, conversationId])
|
||||
const currentConversationId = useMemo(() => conversationId || conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || '', [appId, conversationIdInfo, userId, conversationId])
|
||||
const handleConversationIdInfoChange = useCallback((changeConversationId: string) => {
|
||||
if (appId) {
|
||||
let prevValue = conversationIdInfo?.[appId || '']
|
||||
|
||||
Loading…
Reference in New Issue
Block a user