Repository navigation
feat!: migrate to TypeScript and React function components with hooks - #394
Merged
Merged
Conversation
- Move lib/ to src/ in TypeScript; ChatBot, TextStep, CustomStep and OptionsStep are now function components (useStep, useAutoScroll hooks, pure conversation helpers in src/conversation.ts) - Generate type declarations from src/types.ts instead of index.d.ts - Styled components use transient $props instead of withConfig filtering - Replace webpack/babel with Vite (UMD + ES module builds), mocha/enzyme with Vitest + Testing Library, and use ESLint 9 flat config - Support React 18/19 and styled-components >= 5.1; drop prop-types and random-id
React warned about the non-boolean speaking and invalid attributes when extraControl was a DOM element (e.g. <button />), like the step components already do for DOM elements.
Remove the React Simple Chatbot with AI and Built with sections, and the blogduwebdesign link.
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.
Description
Rewrites React Simple Chatbot in TypeScript with React function components and hooks, and modernizes the tooling. The public API (props, steps, custom components) stays the same, apart from the breaking changes listed below.
What changes
Library
lib/→src/in TypeScript (moved withgit mv, so the history is kept).ChatBot,TextStep,CustomStepandOptionsStepare function components. The conversation logic moved to pure helpers (src/conversation.ts) and hooks (useStep,useAutoScroll,useLatest), and the step state is updated immutably.src/types.ts) instead of the hand-writtenindex.d.ts. New exported type:ChatBotTheme.$props, so style props likewidth,heightandopenedno longer leak into the DOM.extraControl(e.g.<button />) only receivesdisabled, which removes React's "non-boolean attribute" warnings.prop-typesandrandom-iddependencies.Tooling
modulefield).Docs and repo
Security
serialize-javascript,js-yaml,uuid,@tootallnate/once). They came from removed dev dependencies (mocha, nyc, codecov, the old jsdom);js-yamlis now at the patched 4.3.2.npm auditreports 0 vulnerabilities.Where to start reviewing
src/ChatBot.tsx: the main component and the conversation flow (triggerNextStep,submitUserMessage).src/conversation.ts: pure helpers (building the steps, triggers, messages, bubble positions).src/steps_components/common/useStep.tsandsrc/hooks/: delay, trigger-once and auto-scroll logic.tests/unit/ChatBot.spec.tsx: the integration tests describing the expected behavior.Related issue
Closes #393 (Dependabot bump of
serialize-javascriptthrough mocha, which this PR removes).Type of change
feat: new featurefix: bug fixdocs: documentationrefactor/perf/testbuild/ci/chore!, and the migration is described below)How has this been tested?
<script>tags with React 18 + styled-components 5 (3 browsers)The end-to-end tests cover the full conversation, theming, floating mode (mouse, keyboard and controlled), the cache across reloads, the validator, auto-scroll, voice input and speech, the mobile layout, and the custom header and extra control.
Not covered:
<script>tags with styled-components 6 don't work, because its UMD build nests the exports understyled.default. The published 0.7.0 behaves the same (works with styled-components 5, fails with 6), so it is not a regression.Breaking changes
ChatBotis a function component, arefno longer returns a component instanceChatBot; control it with props (e.g.opened+toggleFloating, or a newkeyto restart)keydowninstead of the deprecatedkeypress, and is ignored while composing IME characterskeypresson the input should usekeydownhandleEndreceivesstepsas an object keyed by step id, instead of an array with string keyssteps.someId; replace array methods withObject.values(steps)The version is bumped to 1.0.0 (latest published is 0.7.0).
Checklist
npm run lint,npm run typecheckandnpm testpass