Skip to content

chore: prepare docs for Docusaurus v3 upgrade - 1st iteration#3807

Merged
Simek merged 44 commits intofacebook:mainfrom
slorber:slorber/docs-preparation-docusaurus-v3
Aug 17, 2023
Merged

chore: prepare docs for Docusaurus v3 upgrade - 1st iteration#3807
Simek merged 44 commits intofacebook:mainfrom
slorber:slorber/docs-preparation-docusaurus-v3

Conversation

@slorber
Copy link
Copy Markdown
Contributor

@slorber slorber commented Jul 28, 2023

This PR is the preliminary docs changes that will be required to upgrade to Docusaurus v3.

Docusaurus v3 upgrades MDX from v1 to v2. The new MDX version is better, but the supported syntax is now slightly different (MDX breaking chance):

  • Docusaurus v2 ➡️ MDX v1
  • Docusaurus v3 ➡️ MDX v2

Why is this PR needed?:

  • The Docusaurus v3 upgrade will be done in another PR focusing on code and deps upgrades (Upgrade React-Native website to Docusaurus v3 #3780)
  • The goal of this preliminary work PR is to do upfront docs changes so that the Docusaurus v3 PR is smaller and easier to review, not polluted by required docs syntax changes.
  • The goal of this PR is to replace syntax that does not work with MDX v2 with an alternative that will work both with MDX v1 and v2.

Problematic syntax under MDX v2:

Syntax in MDX v2 is stricter than before and usually require changes related to these chars:

  • {: JSX opening expression
  • <: React opening tag

Possible solutions:

  1. Escape the char: \{ \<
  2. Use the HTML code: &#123; or &#60;
  3. Use code blocks: <XYZ> {x: number, y: number}

There's no single "best solution", it depends on the context and what is less confusing for RNW tech writers.

Escaping (1) can't be applied right now because with Docusaurus v2 (MDX v1) will keep rendering the escaped character:

  • \{ will render as \{ on Docusaurus v2 (bad)
  • \{ will render as { on Docusaurus v3 (good)

The goal is to migrate some problematic docs to a syntax that works both for MDX v1 and v2, and only solutions (2) and (3) match these criteria.

You can test if the syntax work using those playgrounds:


Changes in this PR

I tried to apply one of the 2 possible solutions depending on the context:

  • Sometimes using the HTML code (notably in MD tables)
  • Sometimes wrapping the problematic character in an inline code block

I have added many PR comments to justify each kind of usage and open the discussion to see if that specific change is welcome.


TODO - API types with links

Some docs constructs are harder to handle because they can't be converted to inline code blocks as is due to the Markdown link, for example:

`{nativeEvent: [PressEvent](pressevent)}) => void`

I will try to investigate 2 solutions to handle those, please let me know if you have a preferred one:

I will try to investigate 2 solutions to handle those:
I will try to investigate 2 solutions to handle those:

Inline code block prefix

`md {nativeEvent: [PressEvent](pressevent)}) => void`

Tradeoff:

  • generic and reusable
  • require a Markdown parser loaded on frontend, heavier
  • Docusaurus filename.md extension linking won't work and the link will remain "unprocessed" (but RNW doesn't seem to create md link through file extensions, and only uses pathnames)

Set of MDX API components

The number of problematic cases is relatively small, so it could be possible to create a list of "MDX components" to support each case: <NativeEventPressEventCallback/>

If importing becomes a burden, those components can be added to the global MDX scope.


Process

Before merging this PR, please confirm that all the docs changes made in this PR are welcome and good enough to deploy in production.

Once validated, I will backport them to all the older docs versions.

We don't have to agree on 100% of the changes, in which case I'll revert the unwanted changes, and will have to handle them in the Docusaurus v3 PR (where it will be fine to use escaping \{)


cc @Simek

@netlify
Copy link
Copy Markdown

netlify bot commented Jul 28, 2023

Deploy Preview for react-native ready!

Name Link
🔨 Latest commit dd3e2a6
🔍 Latest deploy log https://app.netlify.com/sites/react-native/deploys/64de6fb5b3a98f0008c4943d
😎 Deploy Preview https://deploy-preview-3807--react-native.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Copy Markdown
Contributor Author

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Please find my update comments, hope it helps to review the PR


While you can browse the source code for React Native on [GitHub](https://github.com/facebook/react-native), we recommend you set up a fork on your local machine.

1. Go to <https://github.com/facebook/react-native>.
Copy link
Copy Markdown
Contributor Author

@slorber slorber Jul 28, 2023

Choose a reason for hiding this comment

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

MDX v2 doesn't like it so it's better to remove it.

< is not necessary here, both MDX v1 and v2 will autolink (cf playgrounds, with GFM plugin enabled for v2).

Review links:

Both render the same:

CleanShot 2023-07-31 at 11 30 54@2x

Comment on lines -112 to -113
accessibilityTraits=“trait”
accessibilityTraits={[“trait”]}
Copy link
Copy Markdown
Contributor Author

@slorber slorber Jul 28, 2023

Choose a reason for hiding this comment

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

Code blocks created through indentation does not work anymore in MDX v2 and cause compilation errors because of the {

Review links:

Both render the same:

CleanShot 2023-07-31 at 11 29 26@2x

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we add the tsx type after the ```?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The syntax is not TS here, and the Docusaurus site has prism.defaultLanguage: 'jsx', so this does not seem required. I can add the language metastring here, but the current code is equivalent to what it used to be.

Do you want me to add tsx for futureproofness? It wouldn't do any harm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cipolleschi I applied ```tsx to those blocks for expliciteness/futureproofness/consistency, as almost all of your other code blocks declare a language.


BTW @Simek unrelated but the fact that prism.defaultLanguage: 'jsx' is applied by default means that Prism is going to try to highlight with JSX all the code blocks that have no language, for example:

-keep class com.facebook.hermes.unicode.** { *; }
-keep class com.facebook.jni.** { *; }
.
├── button.js
└── img
    ├── check.png
    ├── check@2x.png
    └── check@3x.png
"I am bold and red"
0-9: bold
9-17: bold, red

Maybe we need a Docusaurus option like ```undefined to unapply the default? 🤔
In practice it probably does not cause trouble but could some day.

### 9. Create a tracking discussion post

Create a "Road to <YOUR_MINOR_VERSION>" discussion post in the [`react-native-releases`](https://github.com/reactwg/react-native-releases/discussions) working group:
Create a `Road to <YOUR_MINOR_VERSION>` discussion post in the [`react-native-releases`](https://github.com/reactwg/react-native-releases/discussions) working group:
Copy link
Copy Markdown
Contributor Author

@slorber slorber Jul 28, 2023

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Will using square brackets instead of lt/gt characters fix the issue? (Create a "Road to [YOUR_MINOR_VERSION]" discussion post in the...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes! Pushing a fix

CleanShot 2023-08-03 at 19 43 34@2x

### How do I know if my fix/feature is in a certain release?

To determine whether a fix or feature is present in a given release, you will need the commit hash where the fix or feature was added to the `main` branch of the core `react-native` repo. If you know the PR, you can look for the comment from **@facebook-github-bot** that says 'closed this in <COMMIT_HASH>'.
To determine whether a fix or feature is present in a given release, you will need the commit hash where the fix or feature was added to the `main` branch of the core `react-native` repo. If you know the PR, you can look for the comment from **@facebook-github-bot** that says `closed this in <COMMIT_HASH>`.
Copy link
Copy Markdown
Contributor Author

@slorber slorber Jul 28, 2023

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, I prefer this other as "closed this in" is not code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I applied @Simek suggestion for consistency:

CleanShot 2023-08-03 at 19 44 53@2x

Can we keep it or do you prefer an inline code block?

Copy link
Copy Markdown
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

Hi @slorber, thank you so much for investing the time to update our docs.
I left some comments here and there, let me know what do you think and whether they makes sense! :D


- [CommonJS require](https://nodejs.org/docs/latest/api/modules.html)
- [console.{log, warn, error, info, trace, table, group, groupEnd}](https://developer.chrome.com/devtools/docs/console-api)
- [console.&#123;log, warn, error, info, trace, table, group, groupEnd}](https://developer.chrome.com/devtools/docs/console-api)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here I'd rather use a code block. console.log is a piece of code, so it makes sense to have the code.
Also, is a little weird that we have an HTML code for the open parenthesis and the actual closed parenthesis at the end.

| object: {top: number, left: number, bottom: number, right: number} | `{top: 0, left: 0, bottom: 0, right: 0}` |
| Type | Default |
| -------------------------------------------------------------------- | ---------------------------------------- |
| object: `{top: number, left: number, bottom: number, right: number}` | `{top: 0, left: 0, bottom: 0, right: 0}` |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd keep that separate as all the other types (like bool) are not in code blocks.

Comment on lines -112 to -113
accessibilityTraits=“trait”
accessibilityTraits={[“trait”]}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we add the tsx type after the ```?

### How do I know if my fix/feature is in a certain release?

To determine whether a fix or feature is present in a given release, you will need the commit hash where the fix or feature was added to the `main` branch of the core `react-native` repo. If you know the PR, you can look for the comment from **@facebook-github-bot** that says 'closed this in <COMMIT_HASH>'.
To determine whether a fix or feature is present in a given release, you will need the commit hash where the fix or feature was added to the `main` branch of the core `react-native` repo. If you know the PR, you can look for the comment from **@facebook-github-bot** that says `closed this in <COMMIT_HASH>`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, I prefer this other as "closed this in" is not code.

| ({nativeEvent: [PressEvent](pressevent)}) |
| Type |
| ---------------------------------------------- |
| `md ({nativeEvent: [PressEvent](pressevent)})` |
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cipolleschi @Simek @cortinico

This new inline code syntax

`md ({nativeEvent: [PressEvent](pressevent)})`

Turns on a basic support for Markdown links inside

CleanShot 2023-08-04 at 17 46 24

Can you validate this idea?

IMHO this is an UX improvement, considering it's code it should be an inline code block. The non-usage of links before was probably a technical limitation that this new solution enables.

But this requires to teach technical writers to use the `md prefix to turn it on. Considering the current implementation, I prefer to keep it opt-in instead of applied everywhere by default.


Review links:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like it. I don't think that it will be an issue: if a technical writer wants to achieve the same result in these pages, it will likely go here and see how that was achieved and then it will copy the syntax!

// Gives the ability to use basic Markdown links inside inline code blocks
// We use RegExp because a full Markdown parser would be quite heavy
// See https://github.com/facebook/react-native-website/pull/3807
function linkify(input) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cipolleschi @Simek @cortinico

This is the code that enables the ability to use Markdown links inside inline code blocks, leading to this outcome:

CleanShot 2023-08-04 at 17 53 43

This code is included in the client bundles, and I didn't want to include a heavy Markdown parser just for that use case. For that reason I choose to implement partial support (just markdown links), use regexp (less robust) and keep this feature opt-in.

Comment on lines -87 to +105
- [CommonJS require](https://nodejs.org/docs/latest/api/modules.html)
- [console.{log, warn, error, info, trace, table, group, groupEnd}](https://developer.chrome.com/devtools/docs/console-api)
- [XMLHttpRequest, fetch](network.md#content)
- [{set, clear}{Timeout, Interval, Immediate}, {request, cancel}AnimationFrame](timers.md#content)
- [CommonJS `require`](https://nodejs.org/docs/latest/api/modules.html)
- `md [console.{log, warn, error, info, trace, table, group, groupEnd}](https://developer.chrome.com/devtools/docs/console-api)`
- [`XMLHttpRequest`, `fetch`](network.md#content)
- [`{set, clear}{Timeout, Interval, Immediate}, {request, cancel}AnimationFrame`](timers.md#content)

#### ECMAScript 2015 (ES6)

- [Array.from](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
- Array.prototype.{[find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find), [findIndex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)}
- [Object.assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
- String.prototype.{[startsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith), [endsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith), [repeat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat), [includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)}
- [`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
- `md Array.prototype.{[find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find), [findIndex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)}`
- [`Object.assign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
- `md String.prototype.{[startsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith), [endsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith), [repeat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat), [includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)}`

#### ECMAScript 2016 (ES7)

- Array.prototype.[includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
- `md Array.prototype.[includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)`

#### ECMAScript 2017 (ES8)

- Object.{[entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries), [values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)}
- `md Object.{[entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries), [values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)}`
Copy link
Copy Markdown
Contributor Author

@slorber slorber Aug 4, 2023

Choose a reason for hiding this comment

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

@cipolleschi , in reply to your comment

On this page, if we start using inline code blocks, then it's not always clear how to keep it consistent without modifying a bit the content:

  • Should the link wrap the inline code block? (only possible in some cases)
  • Should the link be inside the inline code block? (needed if there's more than 1 link, cf Array.prototype.{xLink,yLink})

To understand better the visual consistency problem:

Before: https://reactnative.dev/docs/next/javascript-environment#polyfills

CleanShot 2023-08-04 at 18 19 18@2x

After: https://deploy-preview-3807--react-native.netlify.app/docs/next/javascript-environment#polyfills

CleanShot 2023-08-04 at 18 22 03@2x

As you can see, it does not visually render exactly the same depending on the order in which you apply the link/inline-code-block, and with current content shape, it's not really possible consistently one pattern or the other (or you would have to use code blocks for things that are not actually code: CommonJS require, XMLHttpRequest, fetch)


Is this consistency problem a blocker, or can we still merge this PR?

It can also be possible to modify the content itself to make it more consistent, because in some cases we have one link to a whole API (console), and sometimes we link to individual functions (Array methods).

In {set, clear}{Timeout, Interval, Immediate}, {request, cancel}AnimationFrame it's quite hard to know where to apply inline code blocks 😅 Note the , in the middle is not code.

Copy link
Copy Markdown
Contributor Author

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Ready for a final review 👍

@Simek
Copy link
Copy Markdown
Collaborator

Simek commented Aug 17, 2023

Thank you for the updates, let's ship it! 🚀

@Simek Simek merged commit 177f8fe into facebook:main Aug 17, 2023
@slorber slorber changed the title chore: prepare docs for Docusaurus v3 upgrade chore: prepare docs for Docusaurus v3 upgrade - iteration 1 Aug 25, 2023
@slorber slorber changed the title chore: prepare docs for Docusaurus v3 upgrade - iteration 1 chore: prepare docs for Docusaurus v3 upgrade - 1st iteration Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants