-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
feat(v2): injectHtmlTags API to inject head and/or body html tags #2057
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 3559a11 |
Deploy preview for docusaurus-preview ready! Built with commit 3559a11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to think about the API and approach for a bit more before committing. Have you seen https://www.gatsbyjs.org/docs/ssr-apis/? We might be able to get some inspiration from it.
packages/docusaurus/src/client/templates/index.html.template.ejs
Outdated
Show resolved
Hide resolved
packages/docusaurus/src/server/html-tags/__tests__/__fixtures__/plugin-both-tags.js
Outdated
Show resolved
Hide resolved
Ready for re-review @yangshun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! 👏
Gimme another day to review it. One question - is there a way to specify |
@yangshun sure no worries & no rush. Was just making sure in case I misunderstood your comment previously. We still have #2048 to address to before alpha.37 release. Lot of commits has been added since alpha.36.
Yes. It's called innerHTML. Edit: I also allow See #2057 (comment) as example on how i injected noflash It's based on html-webpack-plugin HtmlTagObject API so I believe it's very modular & flexible |
<div>test</div> is just
It's like a HTML5 Spec. That's why React has <div dangerouslySetInnerHTML={'test'} />; |
I'll try it! |
@endiliey it's strange, I use your code for noflash, but I don’t see any bugs, I mean, everything works fine! Can you please describe in steps how to reproduce some hydration bug with toggle? |
@lex111 is it ? Maybe css caching or something. Did you make sure you use production build ?
|
@endiliey Oooh, now I see that! But why is this issue not in dev mode? |
@lex111 because dev is just a SPA. Production is staticly rendered HTML (works without JavaScript), and when the JS loads, it hydrates the DOM. Did you try with chrome dev tool ? It's getting correct props. Like if I changed the toggle component to pure text, it's working well. I wonder if its react-toggle bug or something.. |
Aha, I think I might found the problem.
Because in HTML it's actually |
That's the point, props are same. I think we need to additionally set the proper prop in the component itself, as is done in Gatsby. |
Hmm, it's difficult case, but I see in the gif how the toggle changes, can we avoid this? |
@lex111 we can't, unless we don't mind doing it like overreacted io, hiding it. |
Cool! In my opinion this is the best option (?). Using CSS is easy to do it. |
@endiliey yeah, I will care about it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments. I wonder if there's a way/need to make this feature page-specific? They're global as of now which is ok because it's typically meant for global stuff but just wondering if there will be a need for page-specific tags.
@@ -5,8 +5,13 @@ | |||
<meta name="viewport" content="width=device-width"> | |||
<meta name="generator" content="Docusaurus"> | |||
<title><%= htmlWebpackPlugin.options.title %></title> | |||
<%= htmlWebpackPlugin.options.headTags %> | |||
<%= htmlWebpackPlugin.tags.headTags %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this leftover by mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no its not. So html webpack plugin by default will inject the required script at postbody. So since we want to add our own postbody tags, we have to set “inject:false” to htmlwebpackplugin and then put the injection place. See https://github.com/jantimon/html-webpack-plugin/tree/master/examples/custom-insertion-position
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*at posthead and postbody.
<div id="__docusaurus"></div> | ||
<%= htmlWebpackPlugin.tags.bodyTags %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too.
It needs to be done globally IMO. Its because when you go to v2.docusaurus.io, you only load the html once, and the rest of the navigation is using that one HTML and all is just a SPA navigation. |
To make it feature page specific, then we need something like docusaurus-browser or docusaurus-ssr :) Which is kinda different from this PR? |
Motivation
This should partially address #1995 and #2000
Have you read the Contributing Guidelines on pull requests?
yes
Test Plan
Dev
Prod