Fix internal page links rendering with red boxes (CORE-733)#2876
Open
OpenStaxClaude wants to merge 3 commits into
Open
Fix internal page links rendering with red boxes (CORE-733)#2876OpenStaxClaude wants to merge 3 commits into
OpenStaxClaude wants to merge 3 commits into
Conversation
This commit resolves the issue where internal links created in the CMS appear with red boxes due to missing href attributes. The CMS generates links with linktype="page" and id attributes but no href. Changes: - Added resolve-page-links.ts utility that fetches page metadata from the CMS API and populates href attributes for internal page links - Implemented in-memory caching to avoid repeated API calls for the same page ID - Modified raw-html.tsx to automatically resolve page links after rendering HTML content - Added comprehensive unit tests for the resolve-page-links utility - Added integration tests for the RawHTML component with page links The solution processes all HTML content rendered through the RawHTML component, which is used throughout the site for CMS content. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses CORE-733 by resolving CMS-generated internal page links (<a linktype="page" id="...">) that lack href attributes, preventing them from rendering with error styling and enabling proper navigation.
Changes:
- Added a
resolvePageLinkshelper to fetch CMS page metadata and populate missinghrefvalues. - Updated
RawHTMLto invoke page-link resolution after rendering raw HTML content. - Added unit + integration test coverage for link resolution, caching behavior, and error handling.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 14 comments.
| File | Description |
|---|---|
src/app/helpers/resolve-page-links.ts |
Introduces the page-link resolver that finds linktype="page" anchors and sets href via CMS API lookups. |
src/app/components/jsx-helpers/raw-html.tsx |
Hooks the new resolver into RawHTML’s layout effect after HTML injection. |
test/src/helpers/resolve-page-links.test.ts |
Unit tests for the resolver’s behavior (single/multiple links, caching, missing fields, error handling). |
test/src/components/jsx-helpers/raw-html.test.tsx |
Integration tests ensuring RawHTML resolves internal page links and re-resolves on prop changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+31
| // Process all links in parallel | ||
| const promises = Array.from(pageLinks).map(async (link) => { | ||
| const pageId = link.getAttribute('id'); |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes CORE-733 - Internal links created in the CMS appear with red boxes due to missing
hrefattributes.Problem
The CMS (openstax-cms) generates internal page links with the format
<a linktype="page" id="560">link text</a>(nohrefattribute). The os-webview frontend renders these as-is, and CSS styles links without hrefs with red boxes to indicate errors.Solution
This PR modifies os-webview to detect and resolve these internal links by:
linktype="page"and anidattribute/apps/cms/api/v2/pages/{id}/html_urlfield from the API responsehrefattribute to the resolved URLChanges Made
New Files
src/app/helpers/resolve-page-links.ts- Utility function that:[linktype="page"][id]selectorcmsFetchModified Files
src/app/components/jsx-helpers/raw-html.tsx- UpdateduseLayoutEffectto callresolvePageLinksafter rendering HTML contentTests
test/src/helpers/resolve-page-links.test.ts- Unit tests for the resolve-page-links utilitytest/src/components/jsx-helpers/raw-html.test.tsx- Integration tests for RawHTML componentTesting
Acceptance Criteria
Next Steps
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com