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

refactor(docs): theme-common shouldn't depend on docs content #10316

Merged
merged 23 commits into from
Jul 23, 2024

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Jul 19, 2024

Breaking change?

Internal APIs have been moved, this is not considered a breaking change requiring a new major version, although swizzle users might need to update docs/blog theme-common imports in their code:

-import {useDoc} from '@docusaurus/theme-common/internal';
+import {useDoc} from '@docusaurus/plugin-content-docs/client';
-import {useBlogPost} from '@docusaurus/theme-common/internal';
+import {useBlogPost} from '@docusaurus/plugin-content-blog/client';

Motivation

Follow-up of #10313

Note that I added a retro compatibility workaround for APIs from @docusaurus/theme-common that have been moved around. They are public API surfaces although only useCurrentSidebarCategory has ever been documented before v2.1 (not anymore)

TODO as a v4 breaking change:

  • Remove theme-common public API re-rexport
  • Remove theme-common => docs peerDeps
  • Remove blog -> docs peerDeps

Test Plan

CI + preview

Test links

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

Related issues/PRs

@slorber slorber added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Jul 19, 2024
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 19, 2024
Copy link

github-actions bot commented Jul 19, 2024

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO Report
/ 🟠 65 🟢 98 🟢 96 🟢 100 Report
/docs/installation 🟠 55 🟢 97 🟢 100 🟢 100 Report
/docs/category/getting-started 🟠 75 🟢 100 🟢 100 🟠 86 Report
/blog 🟠 68 🟢 96 🟢 100 🟠 86 Report
/blog/preparing-your-site-for-docusaurus-v3 🔴 47 🟢 92 🟢 100 🟢 100 Report
/blog/tags/release 🟠 69 🟢 96 🟢 100 🟠 86 Report
/blog/tags 🟠 75 🟢 100 🟢 100 🟠 86 Report

Copy link

netlify bot commented Jul 19, 2024

[V2]

Name Link
🔨 Latest commit 89b6b5c
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/669e6ba0ca04b60009979f44
😎 Deploy Preview https://deploy-preview-10316--docusaurus-2.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

github-actions bot commented Jul 19, 2024

Size Change: +688 B (+0.01%)

Total Size: 10.9 MB

Filename Size Change
website/build/assets/js/main.********.js 668 kB +303 B (+0.05%)
ℹ️ View Unchanged
Filename Size Change
website/.docusaurus/codeTranslations.json 2 B 0 B
website/.docusaurus/docusaurus.config.mjs 27.4 kB 0 B
website/.docusaurus/globalData.json 30 kB 0 B
website/.docusaurus/i18n.json 930 B 0 B
website/.docusaurus/registry.js 147 kB 0 B
website/.docusaurus/routes.js 71.6 kB 0 B
website/.docusaurus/routesChunkNames.json 75 kB 0 B
website/.docusaurus/site-metadata.json 2.17 kB 0 B
website/build/assets/css/styles.********.css 112 kB 0 B
website/build/blog.html 62.2 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus.html 74.8 kB -1 B (0%)
website/build/blog/2018/04/30/How-I-Converted-Profilo-To-Docusaurus.html 47.2 kB +12 B (+0.03%)
website/build/blog/2018/09/11/Towards-Docusaurus-2.html 51.5 kB +12 B (+0.02%)
website/build/blog/2018/12/14/Happy-First-Birthday-Slash.html 33.2 kB -1 B (0%)
website/build/blog/2019/12/30/docusaurus-2019-recap.html 39.6 kB -1 B (0%)
website/build/blog/2020/01/07/tribute-to-endi.html 34 kB -1 B (0%)
website/build/blog/2021/01/19/docusaurus-2020-recap.html 48.9 kB -1 B (0%)
website/build/blog/2021/03/09/releasing-docusaurus-i18n.html 45.1 kB -1 B (0%)
website/build/blog/2021/05/12/announcing-docusaurus-two-beta.html 52 kB -1 B (0%)
website/build/blog/2021/11/21/algolia-docsearch-migration.html 52.9 kB +12 B (+0.02%)
website/build/blog/2022/01/24/docusaurus-2021-recap.html 44.4 kB -1 B (0%)
website/build/blog/2022/08/01/announcing-docusaurus-2.0.html 142 kB -1 B (0%)
website/build/blog/2022/09/01/docusaurus-2.1.html 50.8 kB -1 B (0%)
website/build/blog/archive.html 24.6 kB 0 B
website/build/blog/page/2.html 65.4 kB 0 B
website/build/blog/page/3.html 83.5 kB 0 B
website/build/blog/page/4.html 58.7 kB 0 B
website/build/blog/page/5.html 39.1 kB 0 B
website/build/blog/preparing-your-site-for-docusaurus-v3.html 138 kB -1 B (0%)
website/build/blog/releases/2.2.html 49.6 kB 0 B
website/build/blog/releases/2.3.html 60.8 kB 0 B
website/build/blog/releases/2.4.html 65.3 kB 0 B
website/build/blog/releases/3.0.html 111 kB +12 B (+0.01%)
website/build/blog/releases/3.1.html 52 kB +1 B (0%)
website/build/blog/releases/3.2.html 48.7 kB 0 B
website/build/blog/releases/3.3.html 55.5 kB 0 B
website/build/blog/releases/3.4.html 55.6 kB +7 B (+0.01%)
website/build/blog/tags.html 28.4 kB 0 B
website/build/blog/upgrading-frontend-dependencies-with-confidence-using-visual-regression-testing.html 128 kB 0 B
website/build/docs.html 49.4 kB +9 B (+0.02%)
website/build/docs/advanced.html 31.1 kB 0 B
website/build/docs/advanced/architecture.html 30.6 kB +4 B (+0.01%)
website/build/docs/advanced/client.html 76 kB 0 B
website/build/docs/advanced/plugins.html 58.6 kB 0 B
website/build/docs/advanced/routing.html 73.9 kB +8 B (+0.01%)
website/build/docs/advanced/ssg.html 81.5 kB 0 B
website/build/docs/api/docusaurus-config.html 200 kB 0 B
website/build/docs/api/misc/@docusaurus/eslint-plugin.html 48.3 kB +4 B (+0.01%)
website/build/docs/api/misc/@docusaurus/eslint-plugin/no-html-links.html 38.1 kB 0 B
website/build/docs/api/misc/@docusaurus/eslint-plugin/no-untranslated-text.html 37 kB 0 B
website/build/docs/api/misc/@docusaurus/eslint-plugin/prefer-docusaurus-heading.html 38.3 kB +4 B (+0.01%)
website/build/docs/api/misc/@docusaurus/eslint-plugin/string-literal-i18n-messages.html 41.9 kB 0 B
website/build/docs/api/misc/@docusaurus/logger.html 39.8 kB 0 B
website/build/docs/api/misc/create-docusaurus.html 34.9 kB 0 B
website/build/docs/api/plugin-methods.html 67.4 kB +4 B (+0.01%)
website/build/docs/api/plugin-methods/extend-infrastructure.html 63 kB +4 B (+0.01%)
website/build/docs/api/plugin-methods/i18n-lifecycles.html 60.6 kB +4 B (+0.01%)
website/build/docs/api/plugin-methods/lifecycle-apis.html 170 kB 0 B
website/build/docs/api/plugin-methods/static-methods.html 46.5 kB +4 B (+0.01%)
website/build/docs/api/plugins.html 31.6 kB 0 B
website/build/docs/api/plugins/@docusaurus/plugin-client-redirects.html 62.6 kB +13 B (+0.02%)
website/build/docs/api/plugins/@docusaurus/plugin-content-blog.html 172 kB +12 B (+0.01%)
website/build/docs/api/plugins/@docusaurus/plugin-content-docs.html 202 kB 0 B
website/build/docs/api/plugins/@docusaurus/plugin-content-pages.html 78 kB 0 B
website/build/docs/api/plugins/@docusaurus/plugin-debug.html 50.5 kB 0 B
website/build/docs/api/plugins/@docusaurus/plugin-google-analytics.html 51.5 kB 0 B
website/build/docs/api/plugins/@docusaurus/plugin-google-gtag.html 51 kB 0 B
website/build/docs/api/plugins/@docusaurus/plugin-google-tag-manager.html 49.8 kB 0 B
website/build/docs/api/plugins/@docusaurus/plugin-ideal-image.html 51.1 kB +4 B (+0.01%)
website/build/docs/api/plugins/@docusaurus/plugin-pwa.html 122 kB +4 B (0%)
website/build/docs/api/plugins/@docusaurus/plugin-sitemap.html 68.5 kB +6 B (+0.01%)
website/build/docs/api/plugins/@docusaurus/plugin-vercel-analytics.html 42.2 kB +12 B (+0.03%)
website/build/docs/api/themes.html 30.4 kB 0 B
website/build/docs/api/themes/@docusaurus/theme-classic.html 46.4 kB +4 B (+0.01%)
website/build/docs/api/themes/@docusaurus/theme-live-codeblock.html 38.6 kB +4 B (+0.01%)
website/build/docs/api/themes/@docusaurus/theme-mermaid.html 37.5 kB +4 B (+0.01%)
website/build/docs/api/themes/@docusaurus/theme-search-algolia.html 34.7 kB 0 B
website/build/docs/api/themes/configuration.html 256 kB +7 B (0%)
website/build/docs/blog.html 211 kB +12 B (+0.01%)
website/build/docs/browser-support.html 51 kB 0 B
website/build/docs/category/getting-started.html 28.3 kB 0 B
website/build/docs/category/guides.html 36.4 kB 0 B
website/build/docs/cli.html 63.8 kB +1 B (0%)
website/build/docs/configuration.html 98.5 kB +4 B (0%)
website/build/docs/create-doc.html 65.3 kB +12 B (+0.02%)
website/build/docs/creating-pages.html 59.1 kB +1 B (0%)
website/build/docs/deployment.html 211 kB +9 B (0%)
website/build/docs/docs-introduction.html 53.6 kB 0 B
website/build/docs/docs-multi-instance.html 78.7 kB +4 B (+0.01%)
website/build/docs/docusaurus-core.html 245 kB 0 B
website/build/docs/guides/whats-next.html 32.8 kB 0 B
website/build/docs/i18n/crowdin.html 151 kB +12 B (+0.01%)
website/build/docs/i18n/git.html 82.6 kB +4 B (0%)
website/build/docs/i18n/introduction.html 50.7 kB 0 B
website/build/docs/i18n/tutorial.html 171 kB +13 B (+0.01%)
website/build/docs/installation.html 73 kB +12 B (+0.02%)
website/build/docs/introduction/index.html 280 B 0 B
website/build/docs/markdown-features.html 83.2 kB +1 B (0%)
website/build/docs/markdown-features/admonitions.html 118 kB +4 B (0%)
website/build/docs/markdown-features/assets.html 93.5 kB +2 B (0%)
website/build/docs/markdown-features/code-blocks.html 245 kB +4 B (0%)
website/build/docs/markdown-features/diagrams.html 56 kB +14 B (+0.03%)
website/build/docs/markdown-features/head-metadata.html 52.8 kB 0 B
website/build/docs/markdown-features/links.html 43.1 kB 0 B
website/build/docs/markdown-features/math-equations.html 95.4 kB +11 B (+0.01%)
website/build/docs/markdown-features/plugins.html 101 kB +8 B (+0.01%)
website/build/docs/markdown-features/react.html 144 kB 0 B
website/build/docs/markdown-features/tabs.html 148 kB 0 B
website/build/docs/markdown-features/toc.html 88.7 kB +4 B (0%)
website/build/docs/migration.html 43 kB -1 B (0%)
website/build/docs/migration/v2.html 41.2 kB 0 B
website/build/docs/migration/v2/automated.html 42.6 kB 0 B
website/build/docs/migration/v2/manual.html 207 kB 0 B
website/build/docs/migration/v2/translated-sites.html 52.8 kB 0 B
website/build/docs/migration/v2/versioned-sites.html 67.2 kB 0 B
website/build/docs/migration/v3.html 218 kB +1 B (0%)
website/build/docs/playground.html 32.5 kB 0 B
website/build/docs/resources/index.html 325 B 0 B
website/build/docs/search.html 121 kB +12 B (+0.01%)
website/build/docs/seo.html 93 kB +13 B (+0.01%)
website/build/docs/sidebar.html 136 kB +4 B (0%)
website/build/docs/sidebar/autogenerated.html 156 kB +13 B (+0.01%)
website/build/docs/sidebar/items.html 188 kB 0 B
website/build/docs/sidebar/multiple-sidebars.html 67.1 kB +4 B (+0.01%)
website/build/docs/static-assets.html 56.2 kB +4 B (+0.01%)
website/build/docs/styling-layout.html 140 kB +3 B (0%)
website/build/docs/support/index.html 319 B 0 B
website/build/docs/swizzling.html 120 kB +14 B (+0.01%)
website/build/docs/team/index.html 310 B 0 B
website/build/docs/typescript-support.html 65.4 kB 0 B
website/build/docs/using-plugins.html 115 kB +13 B (+0.01%)
website/build/docs/versioning.html 87.1 kB +13 B (+0.01%)
website/build/index.html 37.8 kB 0 B

compressed-size-action

Comment on lines 117 to 118
yarn config set packageExtensions --json '{ "@docusaurus/theme-common@*": { "dependencies": { "@docusaurus/plugin-content-docs": "*" } } }'
yarn config set packageExtensions --json '{ "@docusaurus/plugin-content-blog@*": { "dependencies": { "@docusaurus/plugin-content-docs": "*" } } }'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hey @Josh-Cena remember how this yarn pnp thing works?

trying to fix

[success] [webpackbar] Client: Compiled with some errors in 8.99s
Module not found: Error: @docusaurus/theme-common tried to access @docusaurus/plugin-content-docs (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
Required package: @docusaurus/plugin-content-docs
Required by: @docusaurus/theme-common@virtual:6e94eb2be8bb440c1581853dd5cec23b82b14cece8f72bb270f25591c11b4fddad6899fee76fcf8f5b8405f8ff5008c1f7d44fc53a24a1945af23a31a750e3dd#npm:3.4.0-NEW (via /home/runner/work/docusaurus/test-website/.yarn/__virtual__/@docusaurus-theme-common-virtual-725f925b63/4/.yarn/berry/cache/@docusaurus-theme-common-npm-3.4.0-NEW-ae14abdd68-10c0.zip/node_modules/@docusaurus/theme-common/lib/)

Ancestor breaking the chain: @docusaurus/plugin-content-blog@virtual:311126612085e579a3976bffcf0c8410a5b0a22c5[17](https://github.com/facebook/docusaurus/actions/runs/10013274539/job/27680514170?pr=10316#step:9:18)e11607d2bb9fd078431ffba07e4aba5308c7bd73ed15cb0354b2679771dbf6971367c0afad10951965957#npm:3.4.0-NEW
Error:  E2E_TEST: Project has compiler errors.
Error: Process completed with exit code 1.

Copy link
Collaborator

@Josh-Cena Josh-Cena Jul 19, 2024

Choose a reason for hiding this comment

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

Frankly, no—this looks correct but if it doesn't I'm not sure why.

However I'm not sure if such patching in CI is a good thing. We should either add that dependency ourselves or find a way to not do so (such as using a peer dependency and requiring pnp users to declare these as real dependencies).

Copy link
Collaborator Author

@slorber slorber Jul 21, 2024

Choose a reason for hiding this comment

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

But isn't it what I do here, using a peerDependency already?

CleanShot 2024-07-21 at 15 18 11@2x

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey @arcanis @clemyan would you mind helping us find the proper package extensions to get PnP working here?

Afaik you also use pnp on your own Yarn Docusaurus site, so you'd probably need to do the same on your site on next release

https://github.com/yarnpkg/berry/blame/master/.yarnrc.yml#L41

Copy link

@clemyan clemyan Jul 22, 2024

Choose a reason for hiding this comment

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

Package extensions only take effect during an install. For this specific case, moving the yarn add below the yarn config sets will probably resolve it.

As far as I can tell, the current release of preset-classic works out-of-the-box for PnP (We need package extensions on our end only for integration with plugin-typedoc-api), and this change breaks that. So there can be a bigger discussion around supporting PnP if you want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks
Will try to run this locally and see if I can fix it because CI debugging is not super effective 😅

Regarding supporting PnP out of the box I'd be happy to if we can without extensions.

In this PR, the problem is that:

  • I want to move some docs-related public APIs from @docusaurus/theme-common to @docusaurus/plugin-content-docs/client
  • Previously @docusaurus/theme-common depended on @docusaurus/plugin-content-docs
  • Now @docusaurus/plugin-content-docs depend on @docusaurus/theme-common
  • I'd like to use a peer dependency to re-export the moved public APIs from @docusaurus/theme-common, only temporarily for retro-compatibility reasons (will be removed in v4)

Any idea how to do so and still play well with PnP?
Note that this is temporary so if we remove this thing in V4 Docusaurus should work again better in PnP I guess?

Copy link

@clemyan clemyan Jul 22, 2024

Choose a reason for hiding this comment

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

I see you have already made that change for plugin-content-blog and presumably you will do so for plugin-content-pages.

I would say the "correct" way to do this during the transition would be

  • theme-common declares optional peer deps on all 3 content plugins
  • The 3 content plugins declare dependency on theme-common and optional peer deps on the other two content plugins

That way, dependents of preset-classic or theme-classic would see no difference. (Unless the user uses overrides or resolutions, but then the onus is on them)

However, there is the weirdness of having content plugins peer-depend on each other. (though the end users likely wouldn't notice because they are optional)

Also, if someone depends directly on theme-common, they could, for example, use the docs-specific APIs without depending on plugin-content-docs themself. Now they would get a runtime error. Given that this would be a very obscure usecase, I will leave it up to you to decide whether this counts as a breaking change.

Another way to do this is to embrace circularly-dependent packages. During the transition, have theme-common and the 3 content plugins depend on each other. Given your dependencies are declared with exact versions, there is minimal risk of conflicts. Yarn can deal with circular packages, and I strongly believe npm and pnpm also can. (I think babel also has a few circular packages)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @clemyan !

I tried adding docs as a blog peerDeps and apparently it's enough to fix the problem.

Do you think this is a good enough temporary change? Or do you think I should apply your full suggestion (3 plugins depending on each other). I'd prefer to have a minimal solution if possible.

Regarding cyclic dependencies, afaik our TS monorepo (using Lerna) needs to build packages in the correct order, defined by dependencies. I don't think tsc can build one package if its dependency types hasn't been built first, so it would probably writing .d.ts files manually to solve it, or use the new Isolated Declarations thing from TS 5.5. I'd prefer not having a cycle for now.

Copy link

Choose a reason for hiding this comment

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

Upon further inspection, plugins-content-pages has no interaction with theme-common at all? And theme-common only needs plugin-content-docs for BC?

If that's the case, then yes, the peer dependencies you declared should be sufficient. Though ideally they should be marked optional via peerDependenciesMeta.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes for now our page plugin doesn't require theme-common and theme-common only needs docs temporarily for retrocompatibility.

Thanks for your help solving this!

@Josh-Cena
Copy link
Collaborator

Does this fix #7207 or is that issue really worth fixing?

ptgott added a commit to gravitational/docs-website that referenced this pull request Oct 24, 2024
ptgott added a commit to gravitational/docs-website that referenced this pull request Oct 24, 2024
ptgott added a commit to gravitational/docs-website that referenced this pull request Oct 24, 2024
- Upgrade Docusaurus packages to `^3.5.0`
- Fix `@theme/Unlisted` import, since the module declaration was changed
  in facebook/docusaurus#10376.
- Update imports to reflect the movement of some exports from
  `@docusaurus/theme-common/internal` into
  `@docusaurus/plugin-content-docs/client`. See
  facebook/docusaurus#10316.
ptgott added a commit to gravitational/docs-website that referenced this pull request Oct 24, 2024
- Upgrade Docusaurus packages to `^3.5.0`
- Fix `@theme/Unlisted` import, since the module declaration was changed
  in facebook/docusaurus#10376.
- Update imports to reflect the movement of some exports from
  `@docusaurus/theme-common/internal` into
  `@docusaurus/plugin-content-docs/client`. See
  facebook/docusaurus#10316.

Also updates config.json to correct branch names.
mmcallister pushed a commit to gravitational/docs-website that referenced this pull request Oct 24, 2024
- Upgrade Docusaurus packages to `^3.5.0`
- Fix `@theme/Unlisted` import, since the module declaration was changed
  in facebook/docusaurus#10376.
- Update imports to reflect the movement of some exports from
  `@docusaurus/theme-common/internal` into
  `@docusaurus/plugin-content-docs/client`. See
  facebook/docusaurus#10316.

Also updates config.json to correct branch names.
Tankilevitch added a commit to port-labs/ocean that referenced this pull request Nov 20, 2024
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: maintenance This PR does not produce any behavior differences to end users when upgrading.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants