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

Unify HTML template and React component #51

Closed
fmvilas opened this issue Aug 3, 2020 · 5 comments · Fixed by #166
Closed

Unify HTML template and React component #51

fmvilas opened this issue Aug 3, 2020 · 5 comments · Fixed by #166
Labels
enhancement New feature or request

Comments

@fmvilas
Copy link
Member

fmvilas commented Aug 3, 2020

Reason/Context

Currently, we're maintaining this HTML template and the React component. They both serve the same purpose, displaying docs in a browser.

It would be great to unify both somehow so we don't have to maintain the two. Here are my proposals:

Generate the HTML template from the React component using Server-Side Rendering (SSR)

React provides a library called ReactDOMServer that allows us to render a React component using Node.js and get the result as a string. See renderToString().

The HTML template could be an empty template that only contains a generate:after hook, where we run this process of generating the HTML from the React component and save it into an index.html file. This would be enough to render static markup but the elements will not be interactive (i.e., they would not respond to mouse events, etc.). Luckily, we have the ReactDOM.hydrate() method that will make markup interactive.

Generate the HTML template from the React component using client-side bundle.js

This method would be the simplest to accomplish. We generate a bundle.js file from the React component and use it straight in our index.html. We just need to "embed" the asyncapi.yaml file in the index.html file when calling the "render" method. Not as difficult as it may sound.

Downsides I can foresee are:

  1. Bundle size is going to be unnecessarily big? The bundle.js file will have React and all the dependencies included. They will be loaded in the browser every time we visit the docs.
  2. External $ref references will be resolved from the browser every time the docs are opened. The browser may not have enough permissions to get the files or the servers may be unreachable.

I'm all in with the first solution. I'm not yet sure how hydrate works but seems to be powering Next.js, Gatsby, and others; so it should be possible to make markup interactive, and hopefully we don't have to include React and other dependencies in the JS file the browser has to load every time.

Of course, both solutions require us to make React component as good as the HTML template :)

@derberg
Copy link
Member

derberg commented Aug 10, 2020

From my perspective we for sure need to make sure that react component should be usable without react to get wider adoption. We could produce official bundle, similar to the one created by the community and described here -> asyncapi/spec#391

for the html template replacement, I like the idea to do it as Nextjs and Gatsby are doing with react when you use they to generate static websites. Regarding bundle.js:

External $ref references will be resolved from the browser every time the docs are opened. The browser may not have enough permissions to get the files or the servers may be unreachable.

this should not be a problem as we resolve refs first in the generator using parser

"embed" the asyncapi.yaml

we would just make it possible to render spec from inline spec, so template would be super simple, would just inject the asyncapi document available in nunjucks by default

@github-actions
Copy link

github-actions bot commented Nov 1, 2020

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

@github-actions github-actions bot added the stale label Nov 1, 2020
@derberg derberg removed the stale label Nov 2, 2020
@github-actions
Copy link

github-actions bot commented Jan 2, 2021

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

@github-actions github-actions bot added the stale label Jan 2, 2021
@derberg derberg removed the stale label Jan 4, 2021
@github-actions
Copy link

github-actions bot commented Mar 6, 2021

This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️

@magicmatatjahu
Copy link
Member

Related issue in React component - asyncapi/asyncapi-react#265

@magicmatatjahu magicmatatjahu pinned this issue Mar 17, 2021
This was referenced Apr 16, 2021
@magicmatatjahu magicmatatjahu unpinned this issue May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants