facebook / facebook/docusaurus

Allow a single docs folder to be consumed by 2 docs plugin instances (use-case: normal vs embed/iframe docs)

Open
#7,480 25 comments 0 reactions 0 assignees View on GitHub
proposal
Dominant language
TypeScript
Stars
66.2k
Forks
10k
Avg merge
1d 3h
Merged PRs (30d)
52

Description

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#reporting-new-issues).

### Prerequisites

- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the `npm run clear` or `yarn clear` command.
- [X] I have tried `rm -rf node_modules yarn.lock package-lock.json` and re-installing packages.
- [X] I have tried creating a repro with https://new.docusaurus.io.
- [X] 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).

I made a minimal repro codesandbox.

### Reproducible demo

https://codesandbox.io/s/trusting-rosalind-sc4s15

### Steps to reproduce

1. Open the link
2. Open a new tty and type `npm run build`
3. The build will fail.
4. Comment the `plugins` section of the `docusaurus.config.js`
5. Run `npm run build` again.
6. The build will succeed.

### Expected behavior

I should be able to point multiple instances of the docs plugin to the same folder.

### Actual behavior

The build crashes.

### Your environment

- Public source code: N/A
- Public site URL: N/A
- Docusaurus version used: 2.0.0-beta20
- Environment name and version (e.g. Chrome 89, Node.js 16.4): N/A
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): N/A

### Self-service

- [ ] I'd be willing to fix this bug myself.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.