feat(services/markdown): Add support for direct markdown content and update tests#712
Merged
Merged
Conversation
…ontent and update tests
kikoruiz
approved these changes
Sep 30, 2025
davidmartin84
approved these changes
Sep 30, 2025
mariogl
reviewed
Sep 30, 2025
| if (req.readyState === COMPLETED && req.status === STATUS_OK) { | ||
| setHtml(marked(req.responseText)) | ||
| setLoaded(true) | ||
|
|
There was a problem hiding this comment.
This if/else currently covers two branches, but the component actually has three. Since the src prop is no longer required, there’s now a third case where neither src nor contentprops are provided.
What do you think about making the code more defensive and explicitly handling that scenario by returning null? That would be clearer than falling back to the empty string in the state.
if (!content && !src) {
return null
}
if (content) {
setHtml(marked(content))
setLoaded(true)
return
}
if (src) {
const req = new window.XMLHttpRequest()
req.open('GET', src, true)
req.onload = () => {
if (req.readyState === COMPLETED && req.status === STATUS_OK) {
setHtml(marked(req.responseText))
setLoaded(true)
}
}
req.send(null)
}
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.
COMPONENTS/SERVICES/MARKDOWN
✅ Types of changes
📝 Description, Motivation and Context
Add support for direct markdown content for ServicesMarkdown component