Skip to content

fix(app): percent-encode chart and dashboard URL state - #3842

Open
brandon-pereira wants to merge 1 commit into
mainfrom
claude/chart-url-encoding
Open

brandon-pereira wants to merge 1 commit into
mainfrom
claude/chart-url-encoding

Conversation

@brandon-pereira

@brandon-pereira brandon-pereira commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Chart Explorer ?config= and temporary dashboard ?dashboard= state used nuqs' default JSON serializer. It wrote raw JSON into the URL and encoded spaces as +, so links could break when pasted into chat clients or terminals. Both now use the existing parseAsJsonEncoded parser, which writes percent-encoded JSON while still reading legacy raw-JSON links.

Also updates the dashboard unit-test mocks and adds coverage for a SQL config containing quotes, brackets, %, +, and newlines, plus an E2E case that loads a legacy raw-JSON chart link and asserts the rewritten URL is percent-encoded.

How to reproduce

Starting point: any HyperDX deployment with Chart Explorer available, such as the Vercel preview on this PR.

On main:

  1. Open Chart Explorer and switch to SQL mode.
  2. Enter SELECT 1 and run the query.
  3. Copy the URL. The config parameter contains raw JSON and + for spaces:
    /chart?config={%22configType%22:%22sql%22,%22connection%22:%22demo%22,%22source%22:%22demo%22,%22sqlTemplate%22:%22SELECT+1%22}
  4. Paste the link into Slack, Teams, or a terminal. The + can be rewritten or stripped in transit, so the link may no longer restore the chart.

On this branch:

  1. Repeat steps 1–2.
  2. Copy the URL. The config parameter is percent-encoded:
    /chart?config=%7B%22configType%22%3A%22sql%22%2C%22connection%22%3A%22demo%22%2C%22source%22%3A%22demo%22%2C%22sqlTemplate%22%3A%22SELECT%201%22%7D
  3. Paste the link into Slack, Teams, or a terminal. The chart still restores. Existing raw-JSON links also load and are rewritten into the encoded form.

How to test on Vercel preview

Preview routes: /chart

Steps:

  1. Open /chart and switch to SQL mode.
  2. Enter SELECT 1 and run the query.
  3. Verify the config query parameter starts with %7B and contains no raw {, ", spaces, or +.

Validation

  • yarn lint:fix, make ci-lint, cd packages/app && yarn ci:unit
  • Targeted E2E: make dev-e2e FILE=source-name-deeplink GREP="legacy raw-JSON" passed.

Note

Low Risk
Small query-param serialization swap with backward-compatible parsing; low risk to chart explorer and temporary dashboard deep links.

Overview
Chart Explorer ?config= and unsaved dashboard ?dashboard= URL state now serialize with parseAsJsonEncoded instead of nuqs’ default raw JSON parser, so shared links use percent-encoded JSON (no literal {, ", spaces, or + in the param) while still accepting older raw-JSON links.

Unit tests mock parseAsJsonEncoded instead of parseAsJson, queryParsers gains round-trip coverage for SQL configs with tricky characters, and a Playwright case loads a legacy raw-JSON chart link and asserts the URL is rewritten to the encoded form on load.

Reviewed by Cursor Bugbot for commit 7f06a1f. Bugbot is set up for automated code reviews on this repo. Configure here.

@brandon-pereira
brandon-pereira requested a review from a team as a code owner November 26, 2026 20:51
@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f06a1f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 26, 2026 8:55pm UTC
hyperdx-storybook Ready Ready Preview Nov 26, 2026 8:55pm UTC

Request Review

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 2
  • Production lines changed: 10 (+ 133 in test files, excluded from tier calculation)
  • Branch: claude/chart-url-encoding
  • Author: brandon-pereira

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 107 in total (1.11%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 0 P3

None could be anchored to changed lines; they are listed below.

Findings outside the changed lines

  • 🟡 P2 packages/api/src/tasks/checkAlerts/providers/default.ts:654 — Chart Explorer links in alert notifications still use the format this PR is meant to fix → Server-side buildChartExplorerLink still builds config with new URLSearchParams({ config: JSON.stringify(chartConfig) }). That writes form-encoded JSON with + for spaces, and these links go straight to Slack and Teams in alert notifications. So the most common way a /chart?config= link reaches a chat client still has the breakage this PR fixes in the app. To fix it, set the param to encodeURIComponent(JSON.stringify(chartConfig)) before URLSearchParams adds its own layer, which matches encodeJsonUrlParamValue in packages/app/src/utils/urlParamEncoding.ts. Better still, move that helper into common-utils so the API and the app share one encoder. Then update the link assertions in the checkAlerts tests.
  • 🟡 P2 packages/app/src/utils/__tests__/queryParsers.test.ts:129 — New round-trip tests repeat existing parser tests and skip the wiring this PR changes → The new chart config URL round-trip block repeats the existing parseAsJsonEncoded serialize, round-trip and legacy-JSON tests at lines 55-119. It never touches the code the PR actually changes: DBChartPage and useDashboard switching parsers. The dashboard tests (dashboard.test.ts, dashboard.remote.test.ts, useDashboardOnboarding.test.tsx) replace parseAsJsonEncoded with a bare mock, so reverting dashboard.ts to parseAsJson would still pass every test. Add a test that asserts useDashboard calls useQueryState('dashboard', …) with a parser whose serialize output is percent-encoded, and drop or fold in the duplicate parser cases.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

Scope: Swaps nuqs' default parseAsJson serializer for the existing parseAsJsonEncoded parser at two useQueryState call sites — Chart Explorer ?config= (DBChartPage.tsx) and the temporary dashboard ?dashboard= (dashboard.ts) — so shared links percent-encode cleanly instead of using + for spaces. Adds a changeset, updates three unit-test mocks, and adds a round-trip unit test plus a legacy-link E2E.

The swap is sound and backward-compatible: parseAsJsonEncoded.parse tries raw JSON.parse first (legacy raw-JSON links) and falls back to JSON.parse(decodeURIComponent(...)) (new percent-encoded links), and neither parser passes a validator so the as T cast behavior is unchanged from before. No production-breaking issue was found.

✅ No critical issues found.

🟡 P2 — recommended

  • packages/app/src/dashboard.ts:242 — the migrated ?dashboard= call site gets no test that exercises the new encoding; the three dashboard unit tests mock parseAsJsonEncoded to a stub, and the only new round-trip/E2E coverage targets the chart ?config= path.
    • Fix: Add a round-trip or E2E assertion for the dashboard param so its serialize/parse wiring is directly covered like the chart path.
🔵 P3 nitpicks (1)
  • packages/app/src/BenchmarkPage.tsx:138 — the /benchmark page's queries and connections params still use nuqs parseAsJson, leaving the only un-migrated JSON URL params in the app; queries holds raw SQL strings, so benchmark share-links break in Slack/Teams/terminals the same way this PR fixes for charts.
    • Fix: Migrate BenchmarkPage.tsx to parseAsJsonEncoded in a follow-up, or add a comment noting the intentional exclusion.
    • maintainability

Reviewers (10): correctness, security, testing, maintainability, kieran-typescript, julik-frontend-races, project-standards, agent-native, learnings-researcher, previous-comments.

Testing gaps: Dashboard ?dashboard= encoding path has no direct round-trip/E2E coverage (unit tests stub the parser). No test covers a valid-JSON-but-wrong-shape payload reaching the unvalidated cast at either call site — downstream render must tolerate it since no validate guard is wired in.

Notes: The two prior PR comments are from changeset-bot and vercel-bot (automated) — no human review feedback to verify. The changeset (@hyperdx/app patch) matches the change. Both call sites cast URL JSON to SavedChartConfig/Dashboard without a validator; this is pre-existing (identical under the old parseAsJson) and not widened by this diff, but parseAsJsonEncoded accepts an optional validate guard these sites could adopt as hardening.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 482 passed • 1 skipped • 1090s

Status Count
✅ Passed 482
❌ Failed 0
⚠️ Flaky 10
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 7f06a1ff Deployed Nov 26, 2026 by vercel[bot]
Preview – hyperdx-storybook — 7f06a1ff Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant