analog
analog copied to clipboard
injectContentFiles does not provide the actual content: marked(): input parameter is undefined or null
Please provide the environment you discovered this bug in.
I created an minimal examble here: https://github.com/jvoigt/bug-analog-inject-content-files/blob/main/src/app/pages/index.page.ts#L26
Somehow i did not get a stackblitz for it to run.
I tried it on
- node v20.11.0
- npm 10.2.4
- @analogjs/content 1.0.2
Which area/package is the issue in?
content
Description
Thanks tor all the great work. So far i'm realy loving analogjs and am planing to use it in my next project.
I noticed that both injectContent
and injectContentFiles
return a ContentFile
. Only injectContent doing it as Observable.
But to me it looks like, injectContentFiles
does not actually fetch the markdown – the type say it does though. The docs dont mention this. So i would guess the behavoir is actualy working as intended, its just the types and docs that could be more precise.
Please provide the exception or error you saw
So when trying to render the markdown with MarkdownComponent markedjs will produce an Error:
ERROR Error: marked(): input parameter is undefined or null
Please report this to https://github.com/markedjs/marked.
at Marked.parse (@analogjs_content.js?v=5ac38bec:6623:25)
at Function.marked [as parse] (@analogjs_content.js?v=5ac38bec:6741:25)
at _MarkdownContentRendererService.render (@analogjs_content.js?v=5ac38bec:8101:60)
at _AnalogMarkdownComponent.renderContent (@analogjs_content.js?v=5ac38bec:8223:33)
at @analogjs_content.js?v=5ac38bec:8220:130
at doInnerSub (chunk-6QJEESQ7.js?v=5ac38bec:2222:15)
at outerNext (chunk-6QJEESQ7.js?v=5ac38bec:2216:34)
at OperatorSubscriber2._this._next (chunk-6QJEESQ7.js?v=5ac38bec:874:9)`
below i tried the same with injectContent
and it works
Other information
I would guess that the fetching of the markdown is the reason the injectContent
is async.. But the types does not reflect that.
i would be willing to help with fixing that but maybe would require some time and guidance, as i just started experimenting with analog.
I would be willing to submit a PR to fix this issue
- [X] Yes
- [ ] No
I think what is likely happening here is that content
is optional on the type, but in the analog-markdown
component the fallback behaviour for content
being undefined is to use data
defined on the ActivatedRoute
which will not exist, and so it causes the error.
If analog-markdown
is not handling the optional case properly then yes the solution here is probably to restrict the type of injectContentFiles
more so that it omits content
entirely.
I've made some assumptions here that might not be entirely accurate, but maybe that can at least help direct your efforts if you want to work on a PR
hey, sadly i'm quiet busy at the moment... so sadly i wont find time for a pr until some what in the late summer. :(
so if someone wants to pick this up: please do so!