Repository navigation
fix: error on a missing or invalid id - #218
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
[Low impact] The PR appears safe to merge.
|
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Validate the required `id` at config setup. `astro build` throws a clear message; `astro dev` logs the error in the terminal and injects a script that throws in the browser console. Cover both paths with a dedicated playground spec. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1d37d-ff80-71b2-b5de-db8491ba7eb4
d81d81a to
76ffd02
Compare
Amp-Thread-ID: https://ampcode.com/threads/T-01a1dd92-d4a3-750c-a487-f793d5e0b7eb Co-authored-by: Amp <amp@ampcode.com>
This comment was marked as resolved.
This comment was marked as resolved.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1dd92-d4a3-750c-a487-f793d5e0b7eb Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound — the guard now rejects non-string and blank id values and reports through Astro's integration logger in development, so the failure carries the integration name without hand-rolled prefixes.
Reviewed changes — the delta since the prior pullfrog review (8321091..d75244e) tightens the id guard and moves the development report onto Astro's logger.
- Changed the guard to reject blank and non-string
id—typeof id !== "string" || id.trim() === ""replaces!id, so""," ", and123now fail the same way as a missingid. - Routed the development error through Astro's logger —
getInjectableWebAnalyticsContentnow takes the hook'sloggerand callslogger.error, dropping the manual[astro-umami]prefix from the production throw while keeping it in the browser script. - Added coverage for empty and non-string
id— a new test loops over""," ", and123, and the fake hook context supplieslogger.error.
Verified on d75244e: pnpm build and pnpm lint pass, and playwright test tests/default/index.spec.ts --grep 'missing \id`|empty or non-string'passes 3/3.AstroIntegrationLoggeris exported fromastroandloggeris on theastro:config:setup` context in Astro 3.0.0, the oldest supported peer.
deepseek-v4.1-flash-1017 | 𝕏
idid

Problem
idis required by the option type, but a JavaScript Astro config can omit it. The integration currently emitsscript.setAttribute("data-website-id", "undefined"), so the tracker loads with no website ID and silently records nothing.Change
Validate
idat config setup, before any URL parsing:astro buildthrowsTheidoption is required.astro devlogs the same message through Astro's integration logger and injects a small script that throws it in the browser console, so the failure is visible without reading the terminal.idvalues are rejected too, since a JavaScript config bypasses the type.TypeScript already enforces
id: string; this is the runtime guard for JavaScript configs.Tests
playground/tests/default/index.spec.tsdrives the realastro:config:setuphook:astro buildrejects with the messageidvalues reject with the messageChecks
pnpm build— passedpnpm lint— passedpnpm testinplayground— 19/19 passed (17 indefault, plusauto-pageviewandenabled-in-development)Summary by CodeRabbit