You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow a single docs folder to be consumed by 2 docs plugin instances (use-case: normal vs embed/iframe docs) #7480
I have read the console error message carefully (if applicable).
Description
If I add the docs plugin to the list of plugins (multi-instance) and I point it to the same folder that the preset is already pointing to (docs by default), the build process stops working and I see the following errors:
SyntaxError: /code/src/......../index.mdx: Identifier 'React' has already been declared. (46:184)
I believe the bug might be caused by the way each mdx file is being processed. Because a mdx file is (basically) a JSX file, import React from 'react'; is being prepended at the top of each file. But since I have two instances of the docs plugin pointing to the same folder, the import statement is being prepended twice (hence the error).
Interesting. I get why it fails, but I don't understand what you are trying to achieve—what's the use-case? We do expect plugins to work in isolation and their folder paths do not overlap.
I'd like to be able to render the same documentation with different layouts on different URLs. Eg. foo.com/docs/intro should render the navbar, the sidebar, the docs itself, etc..., while foo.com/embedded/intro should render just the intro document, without any other elements (no navbar, no sidebar, no header, no footer, etc...). My use-case is being able to embed a particular document inside an iframe.
Ah, I see. I don't really think you need multiple plugins to do this, but I don't have a better solution on top of my head right now. Because you have the same set of data and metadata, it should be doable within the same plugin, just passing it to two themes.
changed the title [-]Multi-inistance of docs plugin pointing to same folder causes errors[/-][+]Allow same set of docs plugin content to be rendered by multiple themes[/+]on May 24, 2022
I don't really know. I don't think it's possible with today's setup, which is why I'm still leaving it open :) But it's definitely legitimate and we'll figure out a way to do it. Sorry if you think it's going to be a quick little bug fix—it's probably more complicated than we have thought.
@slorber will be back tomorrow, and maybe he can have some opinions to offer as well.
not sure what you mean here 🤷♂️ if you are blocked by this issue please describe what's your use-case and what prevents you to achieve it. Having multiple users reporting their pain helps us choose how we want to solve it
This could allow you to easily plug custom CSS rules depending on the class you inject. For example, you could decide to hide the Docusaurus navbar if the class is present:
html.my-custom-classnav.navbar{display: none;}
The class would be applied to <html> as soon as possible, with static inlined JavaScript (similar to what we do with light/dark theme), so there wouldn't be any flash of unstyled content.
The idea was initially discussed here: #8672 (comment) where we also allow define the Docusaurus theme from a querystring variable (PR: #8708)
I think that this is a good idea! Maybe docusaurus could append that custom docusaurus-html-class query tag to the links that are rendered, so if the user clicks on a link, the frame will load the content with the same styling?
Thanks @alexandernst , that makes sense that the class stays present as the user navigates the embedded document, so that the layout of that element does not switch to the regular layout.
Actually, I'm not sure it would be that easy to add a class name to <html> because of the way react-helmet works: it tends to override classes that are added imperatively afaik. We'll have to test this a bit.
It's possible that allowing users to provide a data-attribute is a safer choice. Once data attributes are set, they should never be overridden. Even if the URL does not contain it anymore (on link click), if we set <html data-embedded="true"/> it should stay there forever (as long as you navigate with SPA/Docusaurus <Link> component).
We would also love embedding the documentation within a (react) app.
Let's say we have a (react) low-code app and some documentation for full platform documentation available on a static website docs.platform.domain
When we're (using the low-code app) for instance editing some entity, we'd love to have an help button that would then display the documentation for the current entity type in the current window, without loading an iframe but rendering a component like so <Docusaurus route="/docs/entity/someentityttye">
That would really be cool! Maybe then we could add some properties to, for instance, show or hide the frame (header, footer, nav, ...)
We'd be ready to invest time and contribute such feature if somehow it makes sens and if it somehow align with the current project architecture :-)
without loading an iframe but rendering a component like so
I don't understand wha you mean here. If it's not an iframe, how can you reference a pathname. You are either rendering a local React component or inside an iframe, I don't see how to do otherwise
That would really be cool! Maybe then we could add some properties to, for instance, show or hide the frame (header, footer, nav, ...)
In #8672 I suggested that we could inject extra classes from querystring params, so that you can decide to show/hide things conditionally.
Just want to chime in and say injectable classes via querystring param would be a big help for us. We maintain a full docs site, but also want to embed certain docs directly in our main application. Being able to drop the navbar element would make the execution much cleaner.
@dvdokkum I implemented it, it should be available in canary today or in v3 alpha/beta/rc/stable a bit later
I only implemented the support for data-attribute injection because with classes it was causing issues on React hydration: React Helmet is erasing the classes that we add inline when it takes over. I think it should be good enough for styling purpose and data-attribute CSS selectors.
In the future it's possible that we design our own official "iframe/embedded mode" but for now we give you the flexibility to implement it yourself. Having your early adopter feedback on this can actually help design the official iframe mode, so please report if it works fine for you.
Yeah, works great, thanks! One thing I am noticing though (probably unrelated?) is that in the Canary release the copy button is no longer appearing on code blocks. Confirmed it wasn't anything I added related this feature, when I pop my version back to @latest the copy buttons come back.
Activity
Josh-Cena commentedon May 24, 2022
Interesting. I get why it fails, but I don't understand what you are trying to achieve—what's the use-case? We do expect plugins to work in isolation and their folder paths do not overlap.
alexandernst commentedon May 24, 2022
I'd like to be able to render the same documentation with different layouts on different URLs. Eg.
foo.com/docs/introshould render the navbar, the sidebar, the docs itself, etc..., whilefoo.com/embedded/introshould render just theintrodocument, without any other elements (no navbar, no sidebar, no header, no footer, etc...). My use-case is being able to embed a particular document inside an iframe.Josh-Cena commentedon May 24, 2022
Ah, I see. I don't really think you need multiple plugins to do this, but I don't have a better solution on top of my head right now. Because you have the same set of data and metadata, it should be doable within the same plugin, just passing it to two themes.
[-]Multi-inistance of docs plugin pointing to same folder causes errors[/-][+]Allow same set of docs plugin content to be rendered by multiple themes[/+]alexandernst commentedon May 24, 2022
How could I do that?
Josh-Cena commentedon May 24, 2022
I don't really know. I don't think it's possible with today's setup, which is why I'm still leaving it open :) But it's definitely legitimate and we'll figure out a way to do it. Sorry if you think it's going to be a quick little bug fix—it's probably more complicated than we have thought.
@slorber will be back tomorrow, and maybe he can have some opinions to offer as well.
alexandernst commentedon May 27, 2022
@slorber Hi! Did you have a chance to look into this proposal?
slorber commentedon May 27, 2022
No, I am reviewing existing PRs for now
6 remaining items
slorber commentedon Jul 13, 2022
No problem, we'll continue investigating.
I also have the use-case for a single folder being consumed by 2 plugins myself, as I'd like to render MDX blog posts in 2 variants:
dustinlacewell commentedon Aug 14, 2022
This is driving me nuts. :( Sorry.
slorber commentedon Aug 16, 2022
not sure what you mean here 🤷♂️ if you are blocked by this issue please describe what's your use-case and what prevents you to achieve it. Having multiple users reporting their pain helps us choose how we want to solve it
slorber commentedon Mar 2, 2023
For the embedding use-case, would it be useful if we allowed applying a global CSS class directly from the iframe query string?
For example:
This could allow you to easily plug custom CSS rules depending on the class you inject. For example, you could decide to hide the Docusaurus navbar if the class is present:
The class would be applied to
<html>as soon as possible, with static inlined JavaScript (similar to what we do with light/dark theme), so there wouldn't be any flash of unstyled content.The idea was initially discussed here: #8672 (comment) where we also allow define the Docusaurus theme from a querystring variable (PR: #8708)
alexandernst commentedon Mar 2, 2023
I think that this is a good idea! Maybe docusaurus could append that custom
docusaurus-html-classquery tag to the links that are rendered, so if the user clicks on a link, the frame will load the content with the same styling?slorber commentedon Mar 2, 2023
Thanks @alexandernst , that makes sense that the class stays present as the user navigates the embedded document, so that the layout of that element does not switch to the regular layout.
Actually, I'm not sure it would be that easy to add a class name to
<html>because of the way react-helmet works: it tends to override classes that are added imperatively afaik. We'll have to test this a bit.It's possible that allowing users to provide a data-attribute is a safer choice. Once data attributes are set, they should never be overridden. Even if the URL does not contain it anymore (on link click), if we set
<html data-embedded="true"/>it should stay there forever (as long as you navigate with SPA/Docusaurus<Link>component).Let's collect a bit more feedback to see what others think.
jbguerraz commentedon Mar 28, 2023
Hello mates 👋 Hello @slorber
We would also love embedding the documentation within a (react) app.
Let's say we have a (react) low-code app and some documentation for full platform documentation available on a static website docs.platform.domain
When we're (using the low-code app) for instance editing some entity, we'd love to have an help button that would then display the documentation for the current entity type in the current window, without loading an iframe but rendering a component like so
<Docusaurus route="/docs/entity/someentityttye">That would really be cool! Maybe then we could add some properties to, for instance, show or hide the frame (header, footer, nav, ...)
We'd be ready to invest time and contribute such feature if somehow it makes sens and if it somehow align with the current project architecture :-)
slorber commentedon Apr 6, 2023
@jbguerraz
I don't understand wha you mean here. If it's not an iframe, how can you reference a pathname. You are either rendering a local React component or inside an iframe, I don't see how to do otherwise
In #8672 I suggested that we could inject extra classes from querystring params, so that you can decide to show/hide things conditionally.
Would this help?
Note we don't implement the behavior for
.embedded-iframe, but we allow you to implement it without duplicating the page for embedding.dvdokkum commentedon May 30, 2023
Just want to chime in and say injectable classes via querystring param would be a big help for us. We maintain a full docs site, but also want to embed certain docs directly in our main application. Being able to drop the navbar element would make the execution much cleaner.
slorber commentedon May 31, 2023
@dvdokkum I implemented it, it should be available in canary today or in v3 alpha/beta/rc/stable a bit later
I only implemented the support for data-attribute injection because with classes it was causing issues on React hydration: React Helmet is erasing the classes that we add inline when it takes over. I think it should be good enough for styling purpose and data-attribute CSS selectors.
#9028
In the future it's possible that we design our own official "iframe/embedded mode" but for now we give you the flexibility to implement it yourself. Having your early adopter feedback on this can actually help design the official iframe mode, so please report if it works fine for you.
dvdokkum commentedon May 31, 2023
Awesome, thank you! I'll give it a whirl later today.
dvdokkum commentedon Jun 1, 2023
Yeah, works great, thanks! One thing I am noticing though (probably unrelated?) is that in the Canary release the copy button is no longer appearing on code blocks. Confirmed it wasn't anything I added related this feature, when I pop my version back to @latest the copy buttons come back.
slorber commentedon Jun 8, 2023
🤷♂️ I still see the copy button. Are you sure?