Skip to content
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

Response example summary is broken in v3 #882

Closed
IanVS opened this issue Jul 5, 2024 · 4 comments
Closed

Response example summary is broken in v3 #882

IanVS opened this issue Jul 5, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@IanVS
Copy link
Contributor

IanVS commented Jul 5, 2024

Describe the bug

I am upgrading from 2.0 beta to 3.0.1, and get several of these errors when I build:

[react-markdown] Warning: please pass a string as `children` (not: `[object Object]`)

I narrowed this down to the use of response example summaries, which worked previously.

Expected behavior

I assume I should be able to continue to provide response example summaries.

Current behavior

[react-markdown] Warning: please pass a string as `children` (not: `[object Object]`)

And the summary does not get rendered

Possible solution

Steps to reproduce

  1. In the petstore demo, add a response example summary, e.g. to /users/login.get.responses."200".content.application/json.examples.response (line 900 right now)
  2. summary: this breaks
  3. clean api docs and build the demo, you'll see a warning when building, and if you visit the page, you won't see the summary and will see a console warning

Context

I have some response examples for certain parameters, e.g.:

            includeCounts:
              summary: Metadata returned when including request params for <code>includeCounts=true</code>, <code>pageSize=1</code>, and <code>cursor="somevalue"</code>.

These are now broken and do not appear in the built results. I tried simplifying this down to just straight text, and it also fails, though at first I thought it was related to the jsx.

I simplified things and logged out what react-markdown was getting as children, and it was this:

image
@IanVS IanVS added the bug Something isn't working label Jul 5, 2024
@IanVS IanVS changed the title Cannot include JSX in example summaries Response example summary is broken in v3 Jul 5, 2024
@sserrata
Copy link
Member

sserrata commented Jul 23, 2024

Hi @IanVS, on first inspection the issue seems to stem from the Markdown theme component - it doesn't appear to render anything in the DOM despite showing up in the generated MDX output. Replacing is with a standard div manually appears to "fix" the issue.

@IanVS
Copy link
Contributor Author

IanVS commented Jul 23, 2024

When I was looking into it, I did a search for the places that react-markdown is used in the plugin, and most places stringify the children, but I think it was the Markdown component that didn't. From what I could tell, it looked like a React.Element was being provided to react-markdown, when it only wanted a string.

@sserrata
Copy link
Member

Turns out I was using the Markdown component incorrectly, or at least I should have chosen a different prop variable from children which is reserved by the create function. This works:

                </TabItem><TabItem
                  label={"response"}
                  value={"response"}
                >
                  <Markdown
                    markdown={"This breaks"}
                  >
                    
                  </Markdown><ResponseSamples
                    responseExample={"OK"}
                    language={"json"}
                  >
                    
                  </ResponseSamples>
                </TabItem>

@sserrata
Copy link
Member

Actually, the more I look into it, seems we don't need the Markdown component (anymore?). Docusaurus v3 appears to render markdown just fine, even if it's inside a div. Seems safe to just replace Markdown with div - I'll open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants