-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
feat(core): add new plugin allContentLoaded lifecycle #9931
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
slorber
added
pr: new feature
This PR adds a new API or behavior.
to backport
This PR is planned to be backported to a stable version of Docusaurus
labels
Mar 8, 2024
slorber
added
the
Argos
Add this label to run UI visual regression tests. See argos.yml GH action.
label
Mar 8, 2024
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
Size Change: 0 B Total Size: 992 kB ℹ️ View Unchanged
|
2 tasks
diemol
added a commit
to saucelabs/elemental-next
that referenced
this pull request
Apr 12, 2024
diemol
added a commit
to saucelabs/elemental-next
that referenced
this pull request
Apr 12, 2024
* fix(deps): update docusaurus monorepo to v3.2.1 * Fix breaking change caused by facebook/docusaurus#9931 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
This was referenced May 19, 2024
This was referenced May 25, 2024
This was referenced Aug 21, 2024
This was referenced Aug 27, 2024
This was referenced Sep 4, 2024
This was referenced Sep 8, 2024
This was referenced Sep 11, 2024
This was referenced Sep 28, 2024
This was referenced Oct 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Argos
Add this label to run UI visual regression tests. See argos.yml GH action.
CLA Signed
Signed Facebook CLA
pr: new feature
This PR adds a new API or behavior.
to backport
This PR is planned to be backported to a stable version of Docusaurus
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important: this feature is considered experimental, and is for now undocumented. Please only use it on your own site plugins, and avoid publishing third-party Docusaurus plugins on npm relying on this lifecycle.
Motivation
Introducing a new
allContentLoaded({allContent, actions})
plugin lifecycle offers the opportunity for plugins to consume data coming from other plugins.This means you can create a plugin aggregating data from multiple plugins/instances, and display that information on a single page. For example, you could use this to create your site homepage and display some docs-related and blog-related info.
If your plugin has both a
contentLoaded
andallContentLoaded
lifecycles, the routes and global data created by both will be shallowly merged.In this case the plugin will have:
/path1
and/path2
{val1: 42, val2: 84, shared: 84}
Limitation: this new lifecycle does not permit to display data from one plugin inside another's page. You can aggregate data for a new brand-new standalone page (such as your homepage), but you cannot display blog posts on a doc page for example. We will try to enable that use case later. Note it remains possible to implement a workaround to extend existing plugins: #4138
Note: technically the existing
contentLoaded
already received theallContent
, but it was a secret undocumented feature (only used by our debug plugin) that is now replaced by this brand-new lifecycle. I won't consider this as a breaking change.An important motivation for this new lifecycle is also the optimization of the dev server (#9903), to provide fine-grained plugin reloads and to avoid wasting CPU/IO running uselessly expensive lifecycles such as
contentLoaded
just because they could eventually read the formerallContent
data.Test Plan
unit tests + dogfood on the debug plugin
Test links
Related issues/PRs
Unlocks further DX optimizations: #9903
Related discussions: #9922 (reply in thread)
The
allContent
data was added to thecontentLoaded
params as part of #3229Example
Reading this PR it might be complex to understand how to aggregate data from multiple plugins on a single page.
Here's an example aggregating the blog posts of 2 separate blogs into a single page.
https://stackblitz.com/edit/github-agngt8?file=MyHomePage%2FMyHomePagePlugin.js,MyHomePage%2FMyHomePage.js,docusaurus.config.js
IMPORTANT: be sure to understand the limits of the current approach. You can create a brand new page on which you display data of multiple plugins, but you can't inject data on an existing page created by an existing plugin. For example it's not possible to show blog posts on a doc page, or to show docs versions on a blog post, because it's not your plugin that creates those pages.
The solution to this problem will be adding support for React Server Components, so that you can access
allContent
directly in your React render tree instead of having to create a plugin. Track #9089