microsoft / microsoft/BotFramework-WebChat
WebChat 4.19.1 crashes when React strict mode is enabled and run locally
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 1.8k
- Forks
- 1.6k
- Avg merge
- 22h 58m
- Merged PRs (30d)
- 2
Description
Is it an issue related to Adaptive Cards?
No
Is this an accessibility issue?
No
What version of Web Chat are you using?
Latest production
Which distribution are you using Web Chat from?
NPM
Which hosting environment does this issue primarily affect?
Web apps
Which browsers and platforms do the issue happened?
Others or unrelated
Which area does this issue affect?
Development experience
Which theme pack does this issue affect?
I did not test it on other theme packs
What is the public URL for the website?
No response
Please describe the bug
After upgrading botframework-webchat in my React 19 app from 4.18.2 to 4.19.1 I got this error in the console when running my app locally:
NotSupportedError: Failed to execute 'define' on 'CustomElementRegistry': the name "webchat-x2s4v--code-block-copy-button" has already been used with this registry
It's related to the React strict mode doing the double mounting of components. When I disabled the strict mode the app worked normally.
Github Copilot analyzed it like this:
It calls
customElements.define()during render-derived initialization without checking whether the generated tag is already registered. React Strict Mode exposes it by replaying the mount in development.
CustomElementsComposerunconditionally invokescustomElements.define()for its generated code-block tags.
I'm using the Composer to render the web chat which is probably related.
Do you see any errors in console log?
NotSupportedError: Failed to execute 'define' on 'CustomElementRegistry': the name "webchat-x2s4v--code-block-copy-button" has already been used with this registry
How to reproduce the issue?
- In React app wrap the app with Strict-component
- Install WebChat 4.19.1
- Render the webchat using Composer-component
- Run the app locally (for example 'npm run dev')
- Open the local site in the browser (any browser will do)
What do you expect?
I expected the WebChat to load normally.
What actually happened?
WebChat didn't load and console had the error mentioned.
Do you have any screenshots or recordings to repro the issue?
No response
Adaptive Card JSON
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Composer component and the CustomElementsComposer mentioned in the report, then reproduce the failure in a React 19 app with Strict Mode enabled. Trace the customElements.define call for the generated code-block tag. Done means WebChat 4.19.1 loads locally under Strict Mode without the duplicate CustomElementRegistry error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- developer-experience, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100