Repository navigation
perf(webview): drop date-fns and react-icons from the webview bundle #2262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
myk1yt
wants to merge
5
commits into
Zoo-Code-Org:main
Choose a base branch
from
myk1yt:chore/dep-swap-round2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1d777ca
perf(webview): replace date-fns formatRelative in McpErrorRow with Intl
myk1yt 121494d
perf(webview): inline the three brand icons instead of react-icons
myk1yt 4f56db9
fix(webview): keep two-digit years in McpErrorRow and freeze the spec…
myk1yt 6e9c944
Merge remote-tracking branch 'origin/main' into chore/dep-swap-round2
myk1yt 0627931
fix(webview): keep react-icons and pin DST/skipped-day parity in McpE…
myk1yt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
164 changes: 164 additions & 0 deletions
164
webview-ui/src/components/mcp/__tests__/McpErrorRow.spec.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import React from "react" | ||
| import { render, screen } from "@/utils/test-utils" | ||
|
|
||
| import { McpErrorRow, formatRelativeTimestamp } from "../McpErrorRow" | ||
|
|
||
| // Thursday 29 October 2026, 12:00 local. Fixed so every expectation below is | ||
| // independent of the machine clock and timezone. | ||
| const BASE = new Date(2026, 9, 29, 12, 0, 0) | ||
|
|
||
| describe("formatRelativeTimestamp", () => { | ||
| // Expected strings captured from date-fns `formatRelative` (en-US) before the | ||
| // swap, so this table pins behaviour equivalence rather than new behaviour. | ||
| it.each([ | ||
| ["same day, earlier", new Date(2026, 9, 29, 9, 0), "today at 9:00 AM"], | ||
| ["same day, later", new Date(2026, 9, 29, 21, 5), "today at 9:05 PM"], | ||
| ["same day, midnight", new Date(2026, 9, 29, 0, 0), "today at 12:00 AM"], | ||
| ["previous day", new Date(2026, 9, 28, 23, 59), "yesterday at 11:59 PM"], | ||
| ["two days back", new Date(2026, 9, 27, 9, 0), "last Tuesday at 9:00 AM"], | ||
| ["six days back", new Date(2026, 9, 23, 9, 0), "last Friday at 9:00 AM"], | ||
| ["seven days back", new Date(2026, 9, 22, 9, 0), "10/22/2026"], | ||
| ["thirty days back", new Date(2026, 8, 29, 9, 0), "09/29/2026"], | ||
| ["four hundred days back", new Date(2025, 8, 24, 9, 0), "09/24/2025"], | ||
| ["next day", new Date(2026, 9, 30, 9, 0), "tomorrow at 9:00 AM"], | ||
| ["two days ahead", new Date(2026, 9, 31, 9, 0), "Saturday at 9:00 AM"], | ||
| ["six days ahead", new Date(2026, 10, 4, 9, 0), "Wednesday at 9:00 AM"], | ||
| ["seven days ahead", new Date(2026, 10, 5, 9, 0), "11/05/2026"], | ||
| ])("formats %s", (_label, date, expected) => { | ||
| expect(formatRelativeTimestamp(date, BASE)).toBe(expected) | ||
| }) | ||
|
|
||
| it("counts calendar days, not elapsed time", () => { | ||
| // Two minutes apart, but on different calendar days. Expected strings | ||
| // verified against date-fns `formatRelative` for the same inputs. | ||
| expect(formatRelativeTimestamp(new Date(2026, 9, 29, 0, 1), new Date(2026, 9, 28, 23, 59))).toBe( | ||
| "tomorrow at 12:01 AM", | ||
| ) | ||
| expect(formatRelativeTimestamp(new Date(2026, 9, 28, 23, 59), new Date(2026, 9, 29, 0, 1))).toBe( | ||
| "yesterday at 11:59 PM", | ||
| ) | ||
| }) | ||
|
|
||
| it("throws on an invalid date", () => { | ||
| expect(() => formatRelativeTimestamp(new Date(Number.NaN), BASE)).toThrow(RangeError) | ||
| }) | ||
|
|
||
| // The maintainer asked for the DST behaviour to be pinned against the | ||
| // replaced helper. Every expectation below was captured by running the real | ||
| // date-fns 4.1.0 `formatRelative` on the same inputs before these tests were | ||
| // written, so they pin parity rather than new behaviour. | ||
| describe("DST and skipped local dates (date-fns 4.1.0 pinned)", () => { | ||
| const withTimeZone = (tz: string, run: () => void) => { | ||
| const hadPreviousTz = "TZ" in process.env | ||
| const previousTz = process.env.TZ | ||
| process.env.TZ = tz | ||
|
|
||
| try { | ||
| run() | ||
| } finally { | ||
| // Restoring with `undefined` would set the literal string | ||
| // "undefined", which Node resolves as UTC; delete instead when the | ||
| // variable was absent so the machine's local zone comes back. | ||
| if (hadPreviousTz) { | ||
| process.env.TZ = previousTz | ||
| } else { | ||
| delete process.env.TZ | ||
| } | ||
| } | ||
| } | ||
|
|
||
| it("counts the skipped Pacific/Apia 2011-12-30 as a full day", () => { | ||
| // Samoa skipped 2011-12-30 entirely when it jumped from UTC-11 to | ||
| // UTC+13. The 12-29 and 12-31 local midnights are only 24h apart, but | ||
| // date-fns reports two calendar days: "Saturday at 12:00 PM". | ||
| withTimeZone("Pacific/Apia", () => { | ||
| const dec29 = new Date(2011, 11, 29, 12, 0) | ||
| const dec31 = new Date(2011, 11, 31, 12, 0) | ||
|
|
||
| expect(dec29.getFullYear()).toBe(2011) | ||
| expect(dec31.getFullYear()).toBe(2011) | ||
| expect(formatRelativeTimestamp(dec31, dec29)).toBe("Saturday at 12:00 PM") | ||
| expect(formatRelativeTimestamp(dec29, dec31)).toBe("last Thursday at 12:00 PM") | ||
| expect(formatRelativeTimestamp(dec29, dec29)).toBe("today at 12:00 PM") | ||
| }) | ||
| }) | ||
|
|
||
| it("rounds a 23-hour spring-forward day to one day", () => { | ||
| // America/New_York, 2026-03-08: 02:00 EST jumps to 03:00 EDT. | ||
| withTimeZone("America/New_York", () => { | ||
| const mar8 = new Date(2026, 2, 8, 12, 0) | ||
| const mar9 = new Date(2026, 2, 9, 12, 0) | ||
|
|
||
| expect(formatRelativeTimestamp(mar9, mar8)).toBe("tomorrow at 12:00 PM") | ||
| expect(formatRelativeTimestamp(mar8, mar9)).toBe("yesterday at 12:00 PM") | ||
| }) | ||
| }) | ||
|
|
||
| it("rounds a 25-hour fall-back day to one day", () => { | ||
| // America/New_York, 2026-11-01: 02:00 EDT repeats as 02:00 EST. | ||
| withTimeZone("America/New_York", () => { | ||
| const nov1 = new Date(2026, 10, 1, 12, 0) | ||
| const nov2 = new Date(2026, 10, 2, 12, 0) | ||
|
|
||
| expect(formatRelativeTimestamp(nov2, nov1)).toBe("tomorrow at 12:00 PM") | ||
| expect(formatRelativeTimestamp(nov1, nov2)).toBe("yesterday at 12:00 PM") | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it("keeps two-digit years instead of remapping them to 1900s", () => { | ||
| // `new Date(99, 11, 31)` would mean 1999. These are real year-99 dates, and | ||
| // the day delta across the year-99/100 boundary must stay one day. | ||
| const year99 = new Date("0099-12-31T12:00:00") | ||
| const year100 = new Date("0100-01-01T12:00:00") | ||
|
|
||
| expect(year99.getFullYear()).toBe(99) | ||
| expect(formatRelativeTimestamp(year99, year100)).toBe("yesterday at 12:00 PM") | ||
| expect(formatRelativeTimestamp(year100, year99)).toBe("tomorrow at 12:00 PM") | ||
| expect(formatRelativeTimestamp(year100, year100)).toBe("today at 12:00 PM") | ||
| }) | ||
| }) | ||
|
|
||
| describe("McpErrorRow", () => { | ||
| // Freeze the clock at a stable midday instant. Without this the component | ||
| // formats against the live `new Date()` while the fixture is built from the | ||
| // live `Date.now()`; in the first five minutes after local midnight the two | ||
| // land on different calendar days and the "today at" assertion fails. | ||
| beforeEach(() => { | ||
| vi.useFakeTimers() | ||
| vi.setSystemTime(new Date(2026, 9, 29, 12, 0, 0)) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers() | ||
| }) | ||
|
|
||
| it("renders the error message and a relative timestamp", () => { | ||
| const timestamp = Date.now() - 5 * 60 * 1000 | ||
|
|
||
| render(<McpErrorRow error={{ message: "Connection refused", timestamp, level: "error" }} />) | ||
|
|
||
| expect(screen.getByText("Connection refused")).toBeInTheDocument() | ||
| expect(screen.getByText("today at 11:55 AM")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("still renders a same-day timestamp just after local midnight", () => { | ||
| // The exact window the flake appeared in: 00:02 local, five minutes ago | ||
| // lands on the previous calendar day, so the phrasing must be "yesterday". | ||
| vi.setSystemTime(new Date(2026, 9, 29, 0, 2, 0)) | ||
|
|
||
| render(<McpErrorRow error={{ message: "late", timestamp: Date.now() - 5 * 60 * 1000, level: "warn" }} />) | ||
|
|
||
| expect(screen.getByText("yesterday at 11:57 PM")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it.each([ | ||
| ["error", "var(--vscode-testing-iconFailed)"], | ||
| ["warn", "var(--vscode-charts-yellow)"], | ||
| ["info", "var(--vscode-testing-iconPassed)"], | ||
| ] as const)("colors the %s level", (level, expectedColor) => { | ||
| render(<McpErrorRow error={{ message: "msg", timestamp: Date.now(), level }} />) | ||
|
|
||
| expect(screen.getByText("msg")).toHaveStyle({ color: expectedColor }) | ||
| }) | ||
| }) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the duplicate
diffdeclaration.Line 45 duplicates the existing dependency on Line 46. The added entry triggers the supplied Biome
lint/suspicious/noDuplicateObjectKeyserror. Delete Line 45 and retain the existing declaration.Biome (2.6.5)
[error] 45-45: The key diff was already declared.
(lint/suspicious/noDuplicateObjectKeys)
Source: Linters/SAST tools