Skip to content

fix(docs): restore hover-only # icons on API docs headings; drop h1 anchors#1229

Merged
baktun14 merged 2 commits into
mainfrom
fix/docs-heading-anchor-hover-and-h1
May 26, 2026
Merged

fix(docs): restore hover-only # icons on API docs headings; drop h1 anchors#1229
baktun14 merged 2 commits into
mainfrom
fix/docs-heading-anchor-hover-and-h1

Conversation

@baktun14
Copy link
Copy Markdown
Contributor

Summary

  • PR fix(docs): scope heading anchors to API documentation only #1228 wrapped the heading-anchor <style is:global> and <script> blocks in docs-layout.astro inside {isApiDocs && (<tag>{}</tag>)} JSX conditionals with the CSS/JS body inside a template literal. Astro's build pipeline mangles that pattern — the production stylesheet for /docs/api-documentation/console-api/api-reference/ truncated to .heading-anchor { .heading-anchor:hover, (missing the opacity: 0 default, so the # icons rendered fully visible all the time), and the clipboard/scrollToHash script was dropped from the page entirely (so refresh-with-hash no longer scrolled to the target).
  • Move the style and script into a new src/components/docs/heading-anchor-assets.astro with raw <style>/<script> bodies (no template literals). The layout becomes {isApiDocs && <HeadingAnchorAssets />}. Astro processes the tags correctly through the component boundary.
  • Drop the <a class="heading-anchor"> wrapper from the page-title <h1>s on the two custom .astro api-docs pages — anchoring to the URL of the page you're already on is meaningless — and configure rehype-autolink-headings with test: ["h2","h3","h4","h5","h6"] so MD/MDX # H1 would also be skipped if anyone adds one.

Test plan

Verified in headless Chromium against astro preview over the freshly built dist/:

  • Built CSS: dist/_astro/_slug_.KcU_Tvib.css contains the full ruleset, including .heading-anchor-icon{opacity:0…}, :where(h1..h6):hover .heading-anchor-icon{opacity:.45}, .heading-anchor:hover .heading-anchor-icon{opacity:.85}. Previously truncated in production.
  • Built JS: dist/_astro/hoisted.BkIvRzCB.js contains the data-anchor-link click handler + scrollToHash + hashchange listener. Previously absent in production.
  • /docs/api-documentation/console-api/api-reference/ — fresh load, mouse off: all 8 sampled .heading-anchor-icon computed opacity: 0 (hidden). Hover one h2 → only that icon becomes visible. Others stay at 0.
  • Same page — click the # next to "Authentication" → URL updates to #authentication, full deep link copied to clipboard, section scrolls into view.
  • Same page — refresh via …/api-reference/#authentication → section lands 249px from viewport top, well below the sticky docs header (was stuck behind it on production).
  • /docs/api-documentation/getting-started/ — same checks pass; main h1 "API Documentation" has no # icon at all.
  • /docs/api-documentation/sdk/quick-start/ (MD/MDX route) — h1 has no anchor (test option works); h2–h6 do; default opacity 0; hover reveals.
  • No leaks to other pages. Checked / (marketing home), /roadmap/2026/, /roadmap/aep-1/, /privacy/: zero .heading-anchor markup, zero scroll-margin-top on [id] headings, anchor-click JS bundle not loaded. Non-api /docs/** pages share the docs layout — they get a 112px scroll-margin-top on id-bearing headings (offsets refresh-scroll below the sticky header — an improvement) and load the JS bundle inertly.

baktun14 added 2 commits May 25, 2026 19:10
PR #1228 wrapped the heading-anchor `<style is:global>` and `<script>`
in `{isApiDocs && (<tag>{`...`}</tag>)}` JSX conditionals with the
CSS/JS body inside a template literal. Astro's build mangles that
pattern: the production stylesheet truncated to
`.heading-anchor { .heading-anchor:hover,` (so the default
`opacity: 0` rule was missing and # icons rendered fully visible),
and the clipboard/scrollToHash script was dropped from the page
entirely (so refresh-with-hash stopped working).

Move the style and script into a dedicated child component with raw
tag bodies (no template literals); the layout just renders
`{isApiDocs && <HeadingAnchorAssets />}`. Astro processes the tags
correctly through the component boundary.

While here, drop the `<a class="heading-anchor">` wrapper from the
page-title `<h1>`s on `api-reference.astro` and
`getting-started.astro` — anchoring to the page URL itself is
meaningless — and configure `rehype-autolink-headings` with
`test: ["h2", ..., "h6"]` so MD/MDX h1s skip the anchor too.
Astro's component parser was matching the literal `<script>` text
inside the frontmatter JS comment as a real script-tag opening,
sliding the script body's start into the comment text and feeding
"tags directly — wrapping them inside a JSX…" to esbuild, which
then failed: `Expected ";" but found "directly"`. Production
`astro build` happened to ignore it; `astro dev` (Vite dep scan)
surfaced the error.

Rewrite the comment without literal tag names.
@baktun14 baktun14 merged commit d7c9da4 into main May 26, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant