Skip to content
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

Remove CodeMirror dependencies #18911

Merged
merged 2 commits into from
Feb 26, 2022
Merged

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Feb 26, 2022

Use webpack dynamic import to load the markdown mode for easymde, eliminating the need to ship the outdated vendored version of codemirror we had, while at the same time updating the markdown mode to the latest version too.

This should also bring a reduction in memory usage because we no long need to include all these unnecessary files in the bindata.

Solution is based on codemirror/codemirror5#5484.

@silverwind
Copy link
Member Author

silverwind commented Feb 26, 2022

The diff is unfortunately spammed by all the file removals. There is only one actual file change in web_src/js/features/comp/EasyMDE.js which is visible via filtering out deleted files in the diff.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 26, 2022
@silverwind silverwind added type/refactoring Existing code has been cleaned up. There should be no new functionality. performance/memory Performance issues affecting memory use labels Feb 26, 2022
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 26, 2022
@silverwind silverwind added this to the 1.17.0 milestone Feb 26, 2022
@silverwind silverwind removed the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Feb 26, 2022
@wxiaoguang
Copy link
Contributor

  1. Is window.CodeMirror = CodeMirror; still needed? If yes, import(/* webpackChunkName: "markdown" */'codemirror/mode/markdown/markdown.js') comes before it, how can it work.
  2. Promise.all doesn't have loading order, what if markdown.js is loaded before codemirror.js?
  3. Should CodeMirror support dynamic plugin loading in future, if yes, does modeURL still work? if no need to support then it's fine.

@silverwind
Copy link
Member Author

1 and 2: It magically appears to work, but you are right there may be race conditions. I guess I will just make it sequentially load. The plugin itself accesses window.CodeMirror on load, I see that this can not have worked but somehow it did.

3: CodeMirror's only purpose is to make EasyMDE work, I don't think we want to extend it further.

@silverwind silverwind changed the title Load CodeMirror mode via webpack and remove vendored CodeMirror Remove CodeMirror dependencies Feb 26, 2022
@silverwind
Copy link
Member Author

I ended up just removing the direct CodeMirror dependency altogether. EasyMDE already loads all the modes and plugins it needs, so there is no reason for neither the webpack dependency nor the vendored copy:

https://github.com/Ionaru/easy-markdown-editor/blob/f573560bb44886d7cc8d412a0b6712f18c3081f0/src/js/easymde.js#L2-L13

Syntax highlighting in EasyMDE still works as expected. I suspect the reason why we left CodeMirror in was because it was previously in direct use by the code editor, which was replaced by monaco.

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

That's what we are glad to see

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 26, 2022
@wxiaoguang wxiaoguang merged commit 329b959 into go-gitea:main Feb 26, 2022
@zeripath
Copy link
Contributor

zeripath commented Feb 26, 2022

Did anyone check if this breaks the Git Hooks editor?

looks fine.

@wxiaoguang
Copy link
Contributor

image

zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 27, 2022
* giteaofficial/main:
  Fix page and missing return on unadopted repos API (go-gitea#18848)
  [skip ci] Updated licenses and gitignores
  Allow adminstrator teams members to see other teams (go-gitea#18918)
  Update nginx reverse proxy docs (go-gitea#18922)
  Don't treat BOM escape sequence as hidden character. (go-gitea#18909)
  Remove CodeMirror dependencies (go-gitea#18911)
  Uncapitalize errors (go-gitea#18915)
  Disable service worker by default (go-gitea#18914)
  Set is_empty in fixtures (go-gitea#18869)
  Don't update email for organisation (go-gitea#18905)
  Correctly link URLs to users/repos with dashes, dots or underscores (go-gitea#18890)
  Set is_private in fixtures. (go-gitea#18868)
  Fix team management UI (go-gitea#18886)
  Update JS dependencies (go-gitea#18898)
  Fix migration v210 (go-gitea#18892)
  migrations: add test for importing pull requests in gitea uploader (go-gitea#18752)
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
EasyMDE already loads all the modes and plugins it needs, so there is no reason for neither the webpack dependency nor the vendored copy
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
@silverwind silverwind deleted the rm-codemirror branch August 5, 2022 20:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. performance/memory Performance issues affecting memory use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants