Skip to content

Remove MarkdownEditor from @primer/react #3604

Closed
@iansan5653

Description

@iansan5653

In order to more easily maintain and iterate on the MarkdownEditor component, we'd like to pull it back into GitHub's internal codebase. As this component never left drafts, we should be able to do this without a breaking change.

The tricky part here is going to be figuring out what to do with the internal dependencies of the component. There are two options, and the correct choice may be different for each dependency:

  1. Remove it from @primer/react and pull it into the internal codebase along with the MarkdownEditor
  2. Expose it publicly from @primer/react so it can be used in the internal codebase and in other places

I've taken a stab at going through the dependency tree and trying to figure out what to do with each thing. Ignoring things that are internal to the component or already public:

  • Internal hooks:
    • useResizeObserver: Let's just expose this publicly by exporting it from hooks/index.ts. I think this is useful and low-risk. Already exposed publicly.
    • useSlots: I think we've previously avoided making this public because it was very unstable, but we seem to have settled on a pattern that works. This would be really useful to have access to in other codebases for making reusable components - let's expose this in hooks/index.ts as well. from drafts.
  • Internal components:
    • VisuallyHidden: This component is private in @primer/react, but is duplicated already in the Memex codebase. I think we should go ahead and just make it public so we can remove the duplication. Maybe we can expose it from @primer/react/drafts? We will duplicate this into the internal codebase.
    • InputLabel (required by MarkdownEditor.Label): This is private in Primer and used in the editor to reuse the styling. I don't think it makes sense to expose this so there's not really a good path here except to just duplicate the styles.
  • Draft components:
    • MarkdownViewer: Migrate this along with MarkdownEditor. This is easy - it has no subdependencies that aren't public.
    • InlineAutocomplete: Migrate
      • This hooks in to FormControl, so we need to make that API public as well
  • Utils:
    • character-coordinates: Migrate, moving internal to InlineAutocomplete
  • Publicly exposed draft hooks: these are public and used fairly often in other codebases. I think we should just leave them behind and keep them publicly exposed in @primer/react/drafts/hooks: We will migrate these as well:
    • useCombobox
    • useDynamicTextareaHeight
    • useIgnoreKeyboardActionsWhileComposing
    • useSafeAsyncCallback
    • useSyntheticChange
    • useUnifiedFileSelect

When done we'll also be able to remove the following dependencies:

  • fzy.js
  • @github/markdown-toolbar-element
  • @github/paste-markdown

I propose we do this in three stages:

  1. Expose the internal code that we want to continue sharing with the editor (useResizeObserver, useSlots, and VisuallyHidden), and cut a release of @primer/react
  2. Copy the to-be-migrated pieces (MarkdownEditor, MarkdownViewer, InlineAutocomplete and dependencies) from this repo into the internal GitHub repo
  3. Delete the migrated code from @primer/react

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions