fix(core): keep same-page anchor links in the same tab#1901
fix(core): keep same-page anchor links in the same tab#1901scottbuscemi wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 8322daf The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
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 |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | 8322daf | Jul 09 2026, 07:50 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | 8322daf | Jul 09 2026, 07:47 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | 8322daf | Jul 09 2026, 07:47 PM |
There was a problem hiding this comment.
This is a focused, well-scoped bug fix: EmDash's own Link.astro component was unconditionally emitting target="_blank" whenever the stored Portable Text link mark had blank: true, which meant plain same-page anchors like #section would open in a new tab. The change forces same-tab behavior only when the resolved href starts with #, leaving external links unchanged.
I checked the changed component, the sanitizeHref utility it depends on, the mark-component map, the new AstroContainer render regression test, and the changeset. The fix is minimal and correct: queries against the sanitized href, so unsafe/empty hrefs that sanitizeHref collapses to "#" also stay same-tab, which is harmless. Relative paths with fragments (/page#section) still respect the existing blank behavior, which matches the stated intent.
The PR also adds a repro test with the expected before/after failure pattern and a proper emdash patch changeset. No localization, SQL, authorization, or API route concerns are involved. LGTM.
Query-count snapshot changes4 routes changed, total Δ +4 queries. SQLite
D1
Comparing snapshot files between base and head. Updated automatically on each push. |
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
What does this PR do?
Fixes same-page anchor links (e.g.
#section) in Portable Text content opening in a new tab. EmDash renders the Portable Textlinkmark via its ownLink.astrocomponent (packages/core/src/components/marks.tsmapslink→Link.astro), which emittedtarget="_blank"whenever the stored mark hadblank: true— with no special-casing for on-page anchors. That meant a same-page jump could open in a new tab, which is never desirable.Link.astronow treats any href starting with#as a same-page anchor and forces same-tab behavior (notarget/rel), regardless of the mark'sblankflag. External links withblank: truestill open in a new tab as before.This is entirely EmDash's own render component — not an upstream Astro /
astro-portabletextdefault.Closes #
Type of change
Checklist
pnpm typecheckpasses (foremdash/core, the changed package; a pre-existing@emdash-cms/cloudflareresolution error requires a core build and is unrelated to this change)pnpm lintpasses (lint:jsonreports 0 diagnostics)pnpm testpasses (or targeted tests for my change) —test:reprosuite greenpnpm formathas been runAI-generated code disclosure
Screenshots / test output
TDD: added
packages/core/tests/repro/link-mark-anchor.render.test.ts(AstroContainer render test). Failed before the fix (#section+blank: truerenderedtarget="_blank"), passes after. Regression guard confirms external links withblank: truestill open in a new tab.