Skip to content

feat(core): allow plugins to declare custom route context#7082

Merged
slorber merged 5 commits intomainfrom
jc/route-context
Apr 7, 2022
Merged

feat(core): allow plugins to declare custom route context#7082
slorber merged 5 commits intomainfrom
jc/route-context

Conversation

@Josh-Cena
Copy link
Collaborator

@Josh-Cena Josh-Cena commented Apr 1, 2022

Motivation

Complete the TODO. Honestly I'm not too sure what we should put here, so I didn't modify the content plugins yet. We already have front matter duplicated twice (once in metadata.frontMatter, once as separate frontMatter injected from MDX loader), I don't really want to duplicate it a third time as that would be disastrous for bundle size.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Builds same as before

Related PRs

@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 lex111 and slorber as code owners April 1, 2022 01:41
@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 51d41b7
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/624ef78f445e020008e12cd5
😎 Deploy Preview https://deploy-preview-7082--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 58
🟢 Accessibility 100
🟠 Best practices 83
🟢 SEO 100
🟢 PWA 90

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

@github-actions
Copy link

github-actions bot commented Apr 1, 2022

Size Change: +1.85 kB (0%)

Total Size: 805 kB

Filename Size Change
website/build/assets/js/main.********.js 612 kB +1.85 kB (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 1, 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.

LGTM 👍 better impl than my first attempt

Comment on lines -107 to -108
// TODO this would be better to do all that in the codegen phase
// TODO handle context for nested routes
Copy link
Collaborator

Choose a reason for hiding this comment

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

these todo look still relevant

for example I don't think it works if you add a context to a doc route, only parent route context work?

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 works everywhere, because it's handled in the same way as route components are handled. As long as there are RouteContextProviders, the nested routes will be properly merged. Unless "nested routes" mean something different here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I think it "works" yes, but only parent routes are namespacing the context data under a "data" attribute while nested routes expose the context data

Maybe if we had a good case to test this feature on docs route we'll see if it works?

This looks fine for now, we'll fix edge cases as soon as we have a use-case for nested context

...genChunkNames({__context: context}, 'context', routePath, res),
...(context
? genChunkNames({__context: context}, 'context', routePath, res)
: {}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

not important but you could replace ternary by && here

image

@slorber slorber merged commit 0a3aad6 into main Apr 7, 2022
@slorber slorber deleted the jc/route-context branch April 7, 2022 16:38
@Josh-Cena Josh-Cena removed the status: awaiting review This PR is ready for review, will be merged after maintainers' approval label Apr 7, 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