-
Notifications
You must be signed in to change notification settings - Fork 46
[WEB-4876] - accept markdown and plain text content types #3144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughEnhanced resilience of markdown fetch in PageHeader component by adding explicit 404 handling, implementing permissive content-type validation supporting text/markdown, application/markdown, and text/plain, and improving error logging with detailed context while preventing crashes on malformed responses. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/components/Layout/mdx/PageHeader.tsx`:
- Around line 71-88: The .md suffix check uses location.pathname, which is the
page path and will rarely end with ".md"; update the logic that builds
isMarkdownType (where contentType and isMarkdownType are defined) to check the
actual fetch/request URL (use response.url or the original request URL) instead
of location.pathname—replace or augment the location.pathname.endsWith('.md')
test with response.url.endsWith('.md') (or equivalent) so the fetch that
requested "`${location.pathname}.md`" is correctly recognized as markdown.
d1ecd33 to
f8ada13
Compare
kennethkalmer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aralovelace, this looks good. The error handling is a bit verbose to my taste, but that is okay. Squash, rebase and ![]()
| const response = await fetch(`${location.pathname}.md`, { | ||
| signal: abortController.signal, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Alternative approach - request markdown explicitly | |
| const response = await fetch(`${location.pathname}.md`, { | |
| signal: abortController.signal, | |
| headers: { 'Accept': 'text/markdown' } | |
| }); |
New implementation respects Accept headers.
curl -I -H "Accept: text/markdown" https://ably.com/docs/platform.md
Earlier we were not sending anything, so it was defaulting to text/plain. This should also fix the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with this approach, we can keep earlier code that explictly checks for text/markdown
i.e.
if (!contentType || !contentType.includes('text/markdown')) {
throw new Error(`Invalid content type: expected text/markdown, got ${contentType}`);
}
Newly added checks for development environments looks okay to me
sacOO7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ( change is optional, but enforces respecting Accept header )
6dc5f51 to
c493e15
Compare
Accepts text/markdown, application/markdown, text/plain, empty/missing content types, or if the URL ends in .md
c493e15 to
c0d4322
Compare
WEB-4876
This page doesnt have Markdown button - https://ably.com/docs/chat/rooms/messages
The issue:
The
PageHeadercomponent allowed too much flexibility when checking whether content was markdown. It treated responses as markdown even when no content type was provided by the server, and it relied on the request path rather than the actual content type. As a result, non-markdown content such as HTML or JSON could be incorrectly handled as markdown when the content type was missing or misleading.The fixes done in this PR:
To Test:
Example page that doesnt have Markdown
review app with fix - https://ably-docs-web-4876-fix--m0bwcs.herokuapp.com/docs/chat/rooms/messages