Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Ignore a saved conversation that doesn't have the expected shape

Đã đóng Phù hợp với người mới
#172 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
frontend, testing

Hướng nghiên cứu

Bắt đầu với load() trong packages/widget/src/storage.ts, sau đó kiểm tra cách init() trong packages/widget/src/widget.ts xử lý khi không có cuộc hội thoại. Thêm các kiểm thử storage cho cấu trúc và thông điệp không hợp lệ, cùng một kiểm thử widget cho {}; issue liệt kê hành vi mong đợi và các lệnh. Công việc hoàn tất khi dữ liệu không hợp lệ bị xóa, các thông điệp hợp lệ được giữ lại, widget khởi chạy với thông điệp chào mừng và build, typecheck, các kiểm thử cùng changeset được yêu cầu đã hoàn thành.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug good first issue hacktoberfest widget

The widget restores the last conversation from localStorage (the chatcops_conversation key, or chatcops_conversation_<siteId>). ConversationStorage.load() returns whatever JSON.parse gives, cast to StoredConversation (packages/widget/src/storage.ts, line 27), and init() uses it as it is (packages/widget/src/widget.ts, lines 185 to 191). When the key holds valid JSON of another shape, for example left by an older version or by another script on the same site, things break. Checked in Chrome with the widget built from dev:

  • {} or []: init() throws a TypeError (messages is not iterable). The chat still opens, but without the welcome message, and with ChatCops.init() the error reaches the page's own code.
  • {"id":"x","messages":[{"foo":1}],"updatedAt":1}: no error, but the chat shows an empty message bubble.

What to do
Check the shape in load(). Return the conversation only when it has a string id and a messages array, and drop messages that don't have a role of user or assistant and string content. Anything else counts as no saved conversation: remove the key and start fresh.

Where to look

  • packages/widget/src/storage.ts (load, lines 23 to 31)
  • packages/widget/src/widget.ts (lines 184 to 193)
  • packages/widget/tests/storage.test.ts and widget.test.ts

Acceptance criteria

  • load() returns null and removes the key when the stored value isn't an object with a string id and a messages array
  • Messages without a user or assistant role or without string content are dropped
  • With {} or [] stored, the widget starts with its welcome message and no error
  • Tests in storage.test.ts for each case, and one in widget.test.ts that init() doesn't throw with {} stored
  • Changeset for @chatcops/widget (patch)
  • pnpm -r build, pnpm -r typecheck and pnpm test pass

Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #172. Setup notes (pnpm, build before test) are in CONTRIBUTING.md.

Ngôn ngữ chính
TypeScript
Star
13
Fork
7
Merge trung bình
4 giờ 11 phút
Pull request đã merge (30 ngày)
122

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của codercops/chatcops

Tất cả issue của codercops/chatcops

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.