Skip to content

Reader: Fix an issue with anchors not working#25459

Merged
kean merged 1 commit intotrunkfrom
fix/anchor-not-working
Mar 27, 2026
Merged

Reader: Fix an issue with anchors not working#25459
kean merged 1 commit intotrunkfrom
fix/anchor-not-working

Conversation

@kean
Copy link
Copy Markdown
Contributor

@kean kean commented Mar 26, 2026

Fixes CMM-1993: iOS: Footnote links in Reader mode redirect to Reader list instead of target location in post and fixes an issue with scroll(to:) ignoring safe area insets, so that the content would end up under it.

Screen.Recording.2026-03-26.at.3.40.25.PM.mov

[Generated] Details and RCA

Defect Summary

Tapping in-document anchor links (e.g. footnotes) in a Reader post navigates the user to the Discover tab instead of scrolling within the article.

Steps to Reproduce

  1. Open any Reader post that contains footnote or anchor links (e.g. 1)
  2. Tap on a footnote superscript link
  3. Expected: The article scrolls to the footnote at the bottom of the post
  4. Actual: The app navigates away to the Reader Discover tab

Root Cause

The issue is caused by a mismatch between the web view's baseURL and the anchor link detection logic in ReaderDetailCoordinator.handle(_:).

Step 1 — baseURL was changed for YouTube embeds.
In a prior change, ReaderWebView.baseURL was set to https://wordpress.com/reader to satisfy Google/YouTube's HTTP referrer requirement. Previously it used the local bundle URL.

Step 2 — Anchor links resolve against baseURL.
When the user taps , WKWebView resolves this relative URL against the baseURL, producing: https://wordpress.com/reader#fn-1

Step 3 — The coordinator fails to recognize it as an in-document anchor.
ReaderDetailCoordinator.handle(_:) checked whether the tapped URL's host+path matched the post's permaLinkURL (e.g. https://example.com/my-post/). Since wordpress.com/reader !=
example.com/my-post/, the check failed.

Step 4 — The URL falls through to the universal link router.
The readerLinkRouter recognizes wordpress.com/reader as a valid Reader route and navigates the user to the Discover tab.

Tap "#fn-1"
→ WKWebView resolves to https://wordpress.com/reader#fn-1
→ handle(_:) checks: does wordpress.com/reader == example.com/my-post? NO
→ Falls through to readerLinkRouter
→ Router matches wordpress.com/reader → navigates to Discover

Fix

Added ReaderWebView.baseURL as a second comparison in the anchor detection logic so that fragment-only links resolved against the web view's base URL are correctly identified as in-document anchors and handled with a scroll instead of navigation.

Secondary Note

The JavaScript anchor fixup code in ReaderWebView.formattedContent(_:) (lines 83–106) is now dead code. It was written to rewrite anchors that started with the bundle URL, but since the baseURL is no longer the bundle URL, it never matches. It is harmless but could be cleaned up in a follow-up.

@kean kean added this to the 26.9 milestone Mar 26, 2026
@kean kean added the Reader label Mar 26, 2026
@kean kean force-pushed the fix/anchor-not-working branch from a1b801b to 5bc4a76 Compare March 26, 2026 19:46
@kean kean requested a review from crazytonyli March 26, 2026 19:46
@sonarqubecloud
Copy link
Copy Markdown

@wpmobilebot
Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number31804
VersionPR #25459
Bundle IDcom.jetpack.alpha
Commit5bc4a76
Installation URL7cdkvljglfblg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number31804
VersionPR #25459
Bundle IDorg.wordpress.alpha
Commit5bc4a76
Installation URL56bke3o2nv0f8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@kean kean added this pull request to the merge queue Mar 27, 2026
Merged via the queue into trunk with commit 133a907 Mar 27, 2026
27 checks passed
@kean kean deleted the fix/anchor-not-working branch March 27, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants