Skip to content

Frontend bug fixes - #396

Merged
leekahung merged 6 commits into
mainfrom
fix/frontend-bug-fixes
Oct 8, 2026
Merged

leekahung merged 6 commits into
mainfrom
fix/frontend-bug-fixes

Conversation

@leekahung

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Infrastructure
  • Maintenance

Description

Fixes several frontend bugs found in a review of the chat, feedback, and letter flows. Each bug was reproduced first, either in the running app or with a test that fails on main.

Chat input

  • Old description sent without the user seeing it: the start-chat box didn't show the saved description. After leaving /chat and coming back, the box looked empty, but "Start Chat" still sent the old text. The box now shows the saved text.
  • Special characters garbled: the start-chat description went through DOMPurify, so < and & reached the backend as &lt; and &amp;. The text is now stored as typed. Rendering was already safe: react-markdown shows HTML as plain text, and follow-up messages never went through DOMPurify.
  • Enter sent half-typed characters: for Chinese/Japanese/Korean input, the Enter that confirms a character also sent the message. It's now ignored while a character is being composed, including Safari's variant of that event (keyCode 229).

Feedback

  • Empty feedback was still submitted: the empty check closed the dialog but didn't stop the send.

  • Double-clicking Send submitted twice.

  • "Feedback Sent!" appeared before the request, and failures were silently lost. The dialog now waits for the request:

    • it shows "Sending…" while the request is in flight;
    • on success it shows "Feedback Sent!" and closes itself after 1.5 s;
    • on failure it shows an error and keeps what the user typed so they can retry.
  • Redaction rewritten. It previously ran a separate regex for each term over the already-escaped transcript. That caused four problems:

    • Terms like C++ or (503 threw an error, and the feedback was never sent.
    • Terms like (503) 555-1234 or $1000 silently didn't match.
    • Terms like amp or 039, or a second term matching the first term's black box, corrupted the transcript HTML.
    • Accented names leaked partly: redacting Jos left the é of José visible.

    Redaction now runs one pass over the raw text with Unicode-aware word boundaries, then escapes the text around the redactions. It doesn't use lookbehind, which Safari below 16.4 can't handle (Vite's default target is safari14).

Letter

  • Every visitor saw "You've been redirected here…": the notice checked for a bare /letter path, which no longer exists. Letter now decides it from the sanitized org value, using a new sanitizeOrg() helper shared with the prompt builder. The notice shows only for real partner links, not for ?org= with an empty or invalid value.

Cleanup

  • Removed the now-unused DOMPurify wrapper, its test, the dompurify dependency and its Architecture.md entries.
  • Removed a mock in Letter.test.tsx that targeted a path that doesn't exist.

Related Tickets & Documents

None.

QA Instructions, Screenshots, Recordings

Tested in Chromium (Playwright against vite dev with /api/* mocked) and in jsdom unit tests. Safari IME behavior is covered by a unit test only.

  1. Old description: on /chat/or, type a description, go to Home, then come back to Chat. The text should still be in the box, and "Start Chat" sends what's shown.
  2. Special characters: start a chat with rent < $1000 & deposit. The request body should contain it exactly as typed.
  3. Letter notice: /letter/or and /letter/or?org=%21%21 show no "redirected" text; /letter/or?org=legal-aid does.
  4. Feedback, success: open Feedback, enter text, and click Send. You should see "Sending…", then "Feedback Sent!", then the dialog closes. Reopening shows empty fields.
  5. Feedback, failure: with /api/feedback returning 500, Send shows an error and keeps the typed text, and retrying works.
  6. Redaction: redact (503) 555-1234, C++ in a chat containing those strings. The transcript shows black boxes and the HTML isn't broken.
  7. Empty or double submit: Send with empty feedback closes the dialog without a request. Double-clicking Send makes one request.

Added/updated tests?

  • Yes. Each fix has a test that fails on main. New files: FeedbackModal.test.tsx and LetterGenerationDialog.test.tsx. New cases in the InitializationForm, InputField, Letter and feedbackHelper tests. 173 tests pass.
  • No, and this is why: please replace this line with details on why tests have not been included
  • I need help with writing tests

Documentation

  • If this PR changes the system architecture, Architecture.md has been updated (removed the DOMPurify entries)

[optional] Are there any post deployment tasks we need to perform?

None.

@leekahung

Copy link
Copy Markdown
Contributor Author

@claude pr-review

@leekahung
leekahung requested a review from yangm2 October 8, 2026 03:03
@claude

claude Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @leekahung's task in 2m 3s —— View job


PR review

  • Gather context and read the diff
  • Review the source changes
  • Review the tests (by reading them only; see the note at the end)
  • Post the review

The PR is in good shape. Every fix has a clear cause, and the fixes are small. The redaction rewrite is the biggest change and it is correct: it matches once on the raw text and escapes only the text around each match. That removes the problems where a term matched inside an HTML entity or inside a black box added for an earlier term. Sorting terms longest first, so a longer term wins over a shorter term it contains, is a good detail. I found no blocking issues. A few small points are below.

Worth addressing

1. "Feedback Sent!" can still show when nothing was sent. (feedbackHelper.ts:60, MessageWindow.tsx:110)
sendFeedback still exits early when messages.length < 2. But the Feedback button appears as soon as messages.length > 0. With a single message, for example while the first answer is still streaming, the modal reaches setStatus("sent") without making any request. The PR description says "Feedback Sent!" now shows only after a successful request, so this case goes against it. Two ways to fix it:

  • throw an error, or return a value the modal can check, instead of exiting quietly; or
  • hide or disable the Feedback button until at least two non-ui messages exist.

Note that the < 2 check counts ui messages, but the transcript leaves them out.

Fix this →

Minor / non-blocking

2. The <a> stripping now runs on pieces of the text. (feedbackHelper.ts:42-46)
sanitizeText removes <a …>…</a> tags, but now it runs separately on each piece of text between redactions. If a redacted term falls inside an anchor, its opening and closing tags end up in different pieces, so the tag is no longer removed. The page stays safe because the text is still escaped. However, the escaped <a href="…"> would show up as visible text in the transcript, and the URL could contain the name being redacted. AI output is markdown, so this rarely happens. If you want to keep the old behavior, remove the anchor tags from the whole message first, then redact and escape. That means splitting sanitizeText into a strip step and an escape step.

3. Closing the modal while a send is in flight. (FeedbackModal.tsx:106-114)
The Close button stays enabled during "sending". If the request then fails, the user never sees the error and loses what they typed. This may be intended, since it lets the user leave. If it isn't, disable Close while sending, as you already do for Send.

4. The error message has no room in the layout. (FeedbackModal.tsx:51-55)
The dialog has a fixed h-[300px]. The children already take more than its full height (h-[80%] + h-[20%] + h-[20%]), so the new <p role="alert"> pushes the inputs further out. This overflow existed before the PR, but the error state makes it worse. Check this visually on the w-[300px] mobile width.

5. Overlapping matches next to each other. The opening delimiter is consumed by the match rather than checked with lookbehind, which is the deliberate trade-off for Safari support. As a result, a term that ends in a non-word character, placed directly before another match (e.g. C++C++), only redacts the first one. This is a very rare edge case and doesn't need a fix. A short comment about it next to NON_WORD could help future readers.

6. e.keyCode is deprecated (InputField.tsx:81). It is still the standard workaround for Safari IME input. The comment explains why it's there, so this is fine as is. Just make sure the lint config doesn't flag the deprecation.

Looks good

  • HousingContext: removing DOMPurify is safe. I found no dangerouslySetInnerHTML anywhere in src/, and the description is only sent to the backend or shown through react-markdown.
  • sanitizeOrg(): moving it into its own helper keeps the prompt and the redirect notice in agreement. ?org=!! correctly results in no notice.
  • Controlled inputs in FeedbackModal and InitializationForm are needed for the retry and "show the saved description" fixes.
  • Auto-close timer: the useEffect cleanup handles the case where the user clicks Close during the 1.5 s delay.
  • fetch: checking response.ok means errors from the server now reach the user.
  • DOMPurify removal: no references to dompurify remain in src/ or in Architecture.md.

Note

I couldn't run npm ci, vitest, lint or tsc in this run because those commands need approval under the current --allowedTools. This review comes from reading the code only. To have CI-style checks included in future reviews, add Bash(npm ci:*) and Bash(npx vitest:*) to the allowed tools.

@leekahung
leekahung requested a review from wittejm October 8, 2026 03:03
@leekahung
leekahung merged commit d881d78 into main Oct 8, 2026
8 checks passed
@leekahung
leekahung deleted the fix/frontend-bug-fixes branch October 8, 2026 04:29
@leekahung leekahung mentioned this pull request Oct 11, 2026
5 of 11 tasks
@leekahung leekahung added bug Something isn't working frontend Frontend implementation (follows UX design) labels Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend Frontend implementation (follows UX design)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants