@chatcops/react: a <ChatCops> component and useChatCops() hook
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
F-12 tasks 2 to 4. A React or Next.js site can use the widget today with useEffect and ChatCops.init(), but everyone writes the same glue, and gets StrictMode or unmounting wrong. This is a small @chatcops/react package that does it once.
'use client';
import { ChatCops, useChatCops } from '@chatcops/react';
export default function Layout({ children }) {
return (
<>
{children}
<ChatCops apiUrl="/api/chat" branding={{ name: 'Acme' }} onLeadCaptured={(lead) => track('lead', lead)} />
</>
);
}
function AskButton() {
const chat = useChatCops();
return <button onClick={() => chat.send('Is this in stock?')}>Ask about this</button>;
}
What to do
- A new
packages/react. Follow "A new package needs" inCONTRIBUTING.md:244("private": true,"type": "module", anexportsentry, the build, typecheck and test scripts).@chatcops/widget(workspace:^) andreact(>=18) are peer dependencies. <ChatCops {...props} />renders nothing. It takesWidgetConfig(exported from@chatcops/widget) plus event props:onOpen,onClose,onMessage,onLeadCaptured,onError(the events areWidgetEventsinpackages/widget/src/widget.ts, around line 139).- Load the widget with a dynamic
import('@chatcops/widget')insideuseEffect, so server rendering outputs nothing and touches nowindow. - It wraps the default
ChatCopsobject frompackages/widget/src/index.ts:36:init()on mount anddestroy()on unmount. A prop change thatupdate()accepts (WidgetUpdate: branding, welcome message, suggestions, placeholder, strings, theme,privacyUrl, disclosure) goes throughChatCops.update(). Any other change, such asapiUrl,modeorcontainer, destroys and inits again. - Event props: subscribe once with
ChatCops.on(), which returns an unsubscribe function (index.ts:124), and keep the latest callback in a ref, so a new arrow function on each render doesn't resubscribe. useChatCops()returns{ open, close, toggle, send, update }, calling the same object (sendissendMessage). Before the widget has loaded, those calls do nothing.- StrictMode runs effects twice in development. Mount, unmount and mount must leave exactly one widget and one set of listeners.
- One
<ChatCops>per page. Say so in the docs. A second one replaces the first, asChatCops.init()does.
Acceptance criteria
- Tests with React Testing Library: it mounts one widget, StrictMode leaves one, unmounting destroys it and removes the listeners, a branding change calls
update()and notinit(), anapiUrlchange inits again,onLeadCapturedfires and survives re-renders, anduseChatCops().send()reachessendMessage - A server-render test:
renderToString(<ChatCops ... />)returns''and doesn't throw - A
.size-limit.jsonentry: the package's own code under 1 kB gzipped, with the widget left out - A "React" page under Widget in the docs, in
website/astro.config.mjs(pnpm docs:checkpasses) - A changeset;
pnpm test:coverage(85/80 for the new package),pnpm lint,pnpm publintandpnpm api(commit the newapi/react.api.md) pass
The tools prop from the F-12 design waits for page tools (F-08), so leave it out.
Comment on this issue to be assigned.
- Lenguaje dominante
- TypeScript
- Estrellas
- 13
- Forks
- 7
- Merge medio
- 3 h 14 min
- PR fusionados (30 d)
- 329
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de codercops/chatcops
-
fix(core): Cohere and Voyage rerankers bypass non-positive limit check on NaN topN and send invalid null payloadPosiblemente ocupada @bhushan4work la tomó hace 1 día. Abiertobug
codercops/chatcops#582 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Widget: a code block tagged `c++`, `c#` or `objective-c` shows part of the tag as codePosiblemente ocupada @prakashNalla la tomó hace 2 días. Abiertobug widget
codercops/chatcops#578 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Docs: Astro, Nuxt and SvelteKit guides for the serverPosiblemente ocupada @anurag2787 la tomó hace 2 días. Abiertodocumentation
codercops/chatcops#575 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Server: chatcopsNext(), one catch-all route for Next.jsPosiblemente ocupada @Saifjafri212213 la tomó hace 2 días. Abiertoenhancement server
codercops/chatcops#574 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 25/100
codercops/chatcops#546 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de codercops/chatcops
Issues similares
-
bug module:nodes tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
rocketride-org/rocketride-server#3020 ·
Los mantenedores suelen responder en 2 días
-
area: dashboard area: tests good first issue size: XS tests
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Read canvas commentsAbiertoenhancement needs-community-review
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
shaharia-lab/slackcli#501 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Bug] Pod detail shows CPU usage ten times too high, and throws on decimal memory suffixesPosiblemente ocupada @RaphaelFakhri la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 11 días
-
`package.json`: build tools listed as runtime dependencies, exact pins causing duplicate installsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
themesberg/flowbite-vue#471 ·