microsoft / microsoft/BotFramework-WebChat

Error in useWebChatUIContext hook never gets thrown

Open
#2,908 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog bug community-help-wanted front-burner p2
Dominant language
HTML
Stars
1.8k
Forks
1.6k
Avg merge
22h 58m
Merged PRs (30d)
2

Description

Version

v 4.7.1

Describe the bug

The useWebChatUIContext hook never throws an error if the context is undefined because the context has a default value and is never undefined.

useWebChatUIContext.js
import { useContext } from 'react';

import WebChatUIContext from '../../WebChatUIContext';

export default function useWebChatUIContext() {
  const context = useContext(WebChatUIContext);

  if (!context) {
    throw new Error('This hook can only be used on a component that is a descendant of <Composer>');
  }

  return context;
}
WebChatUIContext.js
import React from 'react';

const context = React.createContext({
  sendFocusRef: null
});

context.displayName = 'WebChatUIContext';

export default context;

Expected behavior

The error should be thrown when the hook is used outside of the scope of Composer.
[Bug]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with useWebChatUIContext.js and WebChatUIContext.js, comparing the hook's missing-provider check with the context's default value. Verify the hook behavior outside Composer and confirm that it throws the expected error while existing Composer usage continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.