8000 feat(core): fail-safe global data fetching by Josh-Cena · Pull Request #7083 · facebook/docusaurus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(core): fail-safe global data fetching #7083

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

Merged
merged 1 commit into from
Apr 8, 2022
Merged

feat(core): fail-safe global data fetching #7083

merged 1 commit into from
Apr 8, 2022

Conversation

Josh-Cena
Copy link
Collaborator

Motivation

The docs plugin hook can't use fail-fast because "it's used on non-doc pages" (but I think that's probably not the case anymore). But anyways, to avoid refactor hazards I just added a failfast option so we can take advantage of the useAllPluginInstancesData hook.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Build

@Josh-Cena Josh-Cena added the pr: new feature This PR adds a new API or behavior. label Apr 1, 2022
@Josh-Cena Josh-Cena requested review from slorber and lex111 as code owners April 1, 2022 02:29
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 1, 2022
@netlify
Copy link
netlify bot commented Apr 1, 2022

[V2]

Name Link
🔨 Latest commit a9b37dd
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/624fabee3d15550008dc16f3
😎 Deploy Preview https://deploy-preview-7083--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 settings.

@github-actions
Copy link
github-actions bot commented Apr 1, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 61
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-7083--docusaurus-2.netlify.app/

@github-actions
Copy link
github-actions bot commented Apr 1, 2022

Size Change: +56 B (0%)

Total Size: 805 kB

Filename Size Change
website/build/assets/js/main.********.js 612 kB +56 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 49.9 kB
website/build/assets/css/styles.********.css 105 kB
website/build/index.html 38.6 kB

compressed-size-action

@Josh-Cena Josh-Cena added the status: awaiting review This PR is ready for review, will be merged after maintainers' approval label Apr 6, 2022
Copy link
Collaborator
@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.

Mitigated feelings about this.

Is it an API design that users would easily understand?


export function useAllPluginInstancesData(
pluginName: string,
): GlobalData[string];
options?: UseDataOptions,
): GlobalData[string] | undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess it could be possible to use TS overloads to avoid TS users to need to use ! despite the failfast option?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technically yes, but... err... at least not quite useful for us

useAllPluginInstancesData(pluginName: string)
function useAllPluginInstancesData(
pluginName: string,
options?: {failfast?: boolean},
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it really an option that we want to expose publicly? 🤷‍♂️

usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
usePluginData('docusaurus-plugin-content-docs', pluginId, {
failfast: true,
}) as GlobalPluginData;
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably not needed with TS overloads

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's needed because we are casting it to the shape of doc plugin's global data instead of the generic unknown global data. Theoretically we need to validate but in spirit of pragmatism and bundle size I didn't

@Josh-Cena
Copy link
Collaborator Author

So the point is that in the only place where we are using global data, we are using it in a fail-safe way anyways. I think most users would also appreciate a more fail-safe API and handle undefined on their end. We have prior art in useActivePlugin, so this is not unique and I think users can understand it.

@slorber
Copy link
Collaborator
slorber commented Apr 8, 2022

ok 👍 good enough

@slorber slorber merged commit 1719273 into main Apr 8, 2022
@slorber slorber deleted the jc/fail-safe branch April 8, 2022 09:08
@Josh-Cena Josh-Cena removed the status: awaiting review This PR is ready for review, will be merged after maintainers' approval label Apr 8, 2022
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: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0