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

fix(v2): ignore import declarations in excerpt #2380

Merged
merged 3 commits into from
Apr 22, 2020

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Mar 8, 2020

Motivation

Resolve #2373
Resolve #2601

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

Compare MDX page with imports, eg:

Before After
Page: https://deploy-preview-2380--docusaurus-2.netlify.com/docs/migrating-from-v1-to-v2
Description: import ColorGenerator from '@site/src/components/ColorGenerator';
Page: https://v2.docusaurus.io/docs/migrating-from-v1-to-v2/
Description: This doc guides you through migrating an existing Docusaurus 1 site to Docusaurus 2.

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: bug fix This PR fixes a bug in a past release. label Mar 8, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 8, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Mar 8, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 17c093d

https://deploy-preview-2380--docusaurus-2.netlify.app

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import statements can be written anywhere on the page, so if users want to avoid this problem in most cases they can shift it below a little. I rather not add brittle hacks to our code.

packages/docusaurus-utils/src/index.ts Show resolved Hide resolved
@lex111
Copy link
Contributor Author

lex111 commented Mar 21, 2020

But people usually import components at the very beginning of the file, so we are only interested in this place. And given the current architecture, this is a not bad solution.
I also do not consider this patch something like hack, since we need to prepare a description from the MD markup, and accordingly we need to pre-process it. Just the hack is that users will have to move import declarations to another place in the file to get rid of this bug.

@lex111
Copy link
Contributor Author

lex111 commented Mar 26, 2020

Should I close this PR?

@yangshun
Copy link
Contributor

Ok let's close this. Sorry about this.

@yangshun yangshun closed this Mar 26, 2020
@lex111
Copy link
Contributor Author

lex111 commented Mar 26, 2020

No problem, although I did not understand why this is a bad way, given that we need to remove the imports declarations at the top of the file, in the same way we could remove Markdown markup.

@yangshun yangshun deleted the lex111/fix-ignore-imports-excerpt branch March 28, 2020 16:16
@lex111 lex111 restored the lex111/fix-ignore-imports-excerpt branch April 21, 2020 21:55
@lex111
Copy link
Contributor Author

lex111 commented Apr 21, 2020

Reopen after discussion in #2601

@yangshun what other use cases need to be considered?

@lex111 lex111 reopened this Apr 21, 2020
Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Should we filter out require() statements as well? Some people might be using it.

@yangshun yangshun merged commit 84fa4be into master Apr 22, 2020
@yangshun yangshun deleted the lex111/fix-ignore-imports-excerpt branch April 22, 2020 12:28
@lex111 lex111 added this to the v2.0.0-alpha.51 milestone Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
4 participants