drodil / backstage-plugin-qeta

Backstage.io plugin for Q&A
https://www.npmjs.com/package/@drodil/backstage-plugin-qeta
MIT License
81 stars 25 forks source link

bug: Viewing anonymous questions/answers causes crash on frontend #152

Open Revyy opened 4 months ago

Revyy commented 4 months ago

Anonymous questions and answers causes an error in Backstage if the person viewing the question is not the author of the question.

The culprit seems to be this line const { primaryTitle: userName } = useEntityPresentation(entityRef); in UserLink

useEntityPresentation expects a valid entity reference I suppose and since the anonymous check is executed after then it gets passed the string 'anonymous' and crashes.

Moving the if (entityRef === 'anonymous') above useEntityPresentation works but the linter will complain about that since useEntityPresentation is a react hook.

Image of error:

Screenshot 2024-04-24 at 13 57 51

I can create a PR with a possible fix.

drodil commented 4 months ago

Thanks for the report! If you can come up with a PR, it would be much appreciated!

drodil commented 4 months ago

@Revyy can you verify the fix in the new release so we can close this? Thanks!