Repository navigation
fix(widget): persist pre-chat userData and send with every request (#113) - #155
Merged
Merged
Conversation
anurag629
requested changes
Oct 18, 2026
anurag629
left a comment
Member
There was a problem hiding this comment.
Thanks @bhushan4work, that was quick. It works: the answers come back after destroy() and a new Widget, every request carries them, nothing is sent with the form off, and five of the seven new tests fail on dev's code. A few things to tidy before I merge:
getPreChatDataalso readschatcops-prechat-userdata-<id>, but nothing has ever written that key, so the fallback can go.getPreChatUserDataandsetPreChatUserDataonly forward togetPreChatDataandsetPreChatData, and only the tests call them. Please drop them.- The issue asks for a test that the next request after
destroy()and a newWidgetstill carriesuserData. The recreation test only checks the greeting. OnehandleSendonwidget2with the same assertion as in your other test covers it (I tried it, and it passes). tests/setup.tsswaps out storage for every widget test just so the failure tests can replacesetItemandgetItem.vi.spyOn(sessionStorage, 'setItem').mockImplementation(...)works with happy-dom's storage as it is, so the setup file and thevite.config.tschange can go too.
anurag629
approved these changes
Oct 19, 2026
anurag629
left a comment
Member
There was a problem hiding this comment.
Thanks @bhushan4work, all four are done. On top of current dev the build, typecheck and all 272 tests pass, five of the new tests fail with dev's widget code, and the recreation test now checks the request too. I updated the branch with dev so it could merge. Merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change?
Persist pre-chat answers in
sessionStorage, restore them when the widget is recreated in the same tab, and senduserDatawith every request so visitor context is preserved throughout the conversation.Closes #113
How I tested this
pnpm -r buildpnpm testpnpm -r typecheckAI assistance
none
Checklist
devpnpm -r build,pnpm testandpnpm -r typecheckpass locallypnpm changeset) if this changescore,widgetorserver