question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[2.0] RFC: docusaurus swizzle --wrap/copy

See original GitHub issue

šŸš€ Feature

We have a feature to wrap existing theme components: https://docusaurus.io/docs/using-themes#wrapping-theme-components

import OriginalFooter from "@theme-original/Footer";
import React from "react";

export default function Footer(props) {
  return (
    <>
      <div>Before footer</div>
      <OriginalFooter {...props} />
    </>
  );
}

It’s a very useful pattern to use to customize your Docusaurus site. It allows you to enhance a Docusaurus theme without having to copy (and maintain) theme code.

Unfortunately, this feature is not very visible and we don’t encourage its usage, as the code above is only found in our doc, and the swizzle CLI command does not produce such code.

Some use-cases:

  • Add a custom comp before/after (above/under) any existing theme component (like add comments to blog posts)
  • Slightly modify the layout/behavior of an existing theme component (like, add line numbers to code blocks)
  • Add custom MDX components

I suggest to do some changes:

  • Add a docusaurus swizzle --wrap option to produce such code. It wouldn’t require the usage of --danger because it’s way safer than copying.
  • For copying, require explicit usage of --copy option, keep --danger for unsafe components and suggest to prefer usage of --wrap
  • No option: suggest use either --wrap or --copy, hint to prefer --wrap

Other changes to consider in the long term:

  • Rename docusaurus swizzle to something more intuitive like docusaurus theme?
  • Create much smaller theme components, so that users naturally have more before/after wrapping possibilities to suit their use-cases.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Josh-Cenacommented, Jan 7, 2022

Great, you can go ahead šŸ‘ I would be relaxing a little

1reaction
Josh-Cenacommented, Aug 19, 2021

Rename docusaurus swizzle to something more intuitive like docusaurus theme?

  1. I like swizzle because it sounds funky šŸ˜›
  2. We probably want a verb here instead of a noun
  3. Agree that swizzle is not intuitive enough

Create much smaller theme components, so that users naturally have more before/after wrapping possibilities to suit their use-cases.

Agreed. I also think a more hierarchical component structure is better than crowding src/theme with all kinds of components, since it makes navigation and understanding the components’ usage easier.

No strong feelings about extending the CLI. I think we can make it fully interactive (just like docusaurus-init) so that running docusaurus swizzle will prompt you for wrap/copy, the theme, and the component, step by step. Right now if the theme name / component name isn’t provided it throws an exit code: 1 in my face which I don’t like. If user just wants to list the components/themes available but not to actually choose any of them, they can either provide an explicit --list argument or choose a quit option in the interactive console.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swizzling - Docusaurus
Ejecting: creates a copy of the original theme component, which you can fully customize; Wrapping: creates a wrapper around the original themeĀ ...
Read more >
2.0.0-rc.1 - Docusaurus
#7776 fix(core): swizzle --eject js should not copy theme .d.ts files (@slorber) Ā· #7750 fix(deploy): revert "feat(deploy): copy local git configĀ ...
Read more >
Announcing Docusaurus 2.0
Today we are extremely happy to finally announce Docusaurus 2.0! ... React component provided by our default theme: we call this swizzling.
Read more >
CLI - Docusaurus
Docusaurus CLI commands​ Ā· docusaurus start [siteDir] ​ Ā· docusaurus build [siteDir] ​ Ā· docusaurus swizzle [themeName] [componentName] [siteDir] ​.
Read more >
Styling and Layout - Docusaurus
refer to the swizzling guide. A Docusaurus site is a single-page React application. You can style it the way you style React apps....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found