Skip to content

Add html lang prop to CodeEditor Component inside the SourceCodeModal - #2043

Merged
brian-smith-tcril merged 4 commits into
openedx:masterfrom
tonybusa:html-button-in-text-component-editor
Jun 2, 2025
Merged

Add html lang prop to CodeEditor Component inside the SourceCodeModal#2043
brian-smith-tcril merged 4 commits into
openedx:masterfrom
tonybusa:html-button-in-text-component-editor

Conversation

@tonybusa

@tonybusa tonybusa commented May 29, 2025

Copy link
Copy Markdown
Contributor

Description

Fixes: openedx/wg-build-test-release#466

Useful information to include:

  • Which edX user roles will this change impact? "Course Author"

Screen Recording 2025-05-29 at 12.00.01 PM

Testing instructions

Go to Section > Subsection > Unit (Text)
Click on the "text" button in the Add Components panel
Text editor opens in a modal
Click on the text editor HTML functions

Other information

The CodeEditor hook createCodeMirrorDomNode is doing a lookup on CODEMIRROR_LANGUAGES but we never set the lang on the component. Since this is referenced in the project to be specifically an HTML editor, I hardcoded the "html" string to the prop for the lookup to succeed. Otherwise, there is a new change on master that includes the default as xml() (this wasn't included in the current teak release).
See default here: https://github.com/tonybusa/frontend-app-authoring/blob/html-button-in-text-component-editor/src/editors/sharedComponents/CodeEditor/hooks.js#L103

@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @tonybusa!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@tonybusa
tonybusa requested a review from Copilot May 29, 2025 18:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue with the CodeEditor hook lookup by explicitly setting the language property to "html" on the CodeEditor component. The changes include updating the CodeEditor prop in the SourceCodeModal component and its corresponding snapshot to reflect this fix.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/editors/sharedComponents/SourceCodeModal/index.jsx Added lang="html" to ensure proper lookup in CODEMIRROR_LANGUAGES
src/editors/sharedComponents/SourceCodeModal/snapshots/index.test.jsx.snap Updated snapshot to reflect the new lang prop

Comment thread src/editors/sharedComponents/SourceCodeModal/index.jsx Outdated
@codecov

codecov Bot commented May 29, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.99%. Comparing base (01243af) to head (8248abb).
Report is 15 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #2043    +/-   ##
========================================
  Coverage   93.98%   93.99%            
========================================
  Files        1155     1155            
  Lines       24146    24177    +31     
  Branches     5116     5241   +125     
========================================
+ Hits        22693    22724    +31     
+ Misses       1385     1376     -9     
- Partials       68       77     +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tonybusa
tonybusa force-pushed the html-button-in-text-component-editor branch 2 times, most recently from 13445fe to 67b85c9 Compare May 29, 2025 19:18
@tonybusa
tonybusa force-pushed the html-button-in-text-component-editor branch from 67b85c9 to 8248abb Compare May 29, 2025 19:25
@mariajgrimaldi

Copy link
Copy Markdown
Member

@mphilbrick211: can you help us find a reviewer? This PR solves a high priority issue for the Teak release :)

@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label May 30, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions May 30, 2025
@mphilbrick211

Copy link
Copy Markdown

@openedx/committers-frontend - would someone be able to take a look at this?

@brian-smith-tcril brian-smith-tcril added the create-sandbox open-craft-grove should create a sandbox environment from this PR label May 30, 2025
@brian-smith-tcril

Copy link
Copy Markdown
Contributor

It's not clear to me why we'd want this new fix instead of just backporting #1869 to Teak. Also, since this is targeting master, does that mean we want to have both this and #1869?

@brian-smith-tcril

Copy link
Copy Markdown
Contributor

For additional context: I was not able to reproduce the issue on master (clicking on the "HTML" button seems to work as expected there for me)

@open-craft-grove

Copy link
Copy Markdown

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@tonybusa

Copy link
Copy Markdown
Contributor Author

@brian-smith-tcril I explained the difference in this change in the "Other Information" section of the PR description. Sorry if you've already read that and your asking for a more clear explanation. But basically the fix you reference is defaulting to xml() and not actually using the lookup to get html(). Also referenced here: openedx/wg-build-test-release#466 (comment)

@brian-smith-tcril brian-smith-tcril left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alright, so I think I'm finally fully following this now.

Before #1869 we had:

export const createCodeMirrorDomNode = ({
  ref,
  initialText,
  upstreamRef,
  lang,
}) => {
  // eslint-disable-next-line react-hooks/rules-of-hooks
  useEffect(() => {
    const languageExtension = CODEMIRROR_LANGUAGES[lang]();

and this instance of the CodeEditor component didn't have a lang prop set, causing the error.

That was changed in #1869 to be

export const createCodeMirrorDomNode = ({
  ref,
  initialText,
  upstreamRef,
  lang,
}) => {
  // eslint-disable-next-line react-hooks/rules-of-hooks
  useEffect(() => {
    const languageExtension = CODEMIRROR_LANGUAGES[lang] ? CODEMIRROR_LANGUAGES[lang]() : xml();

which fixes the error by handling the lack of lang prop by defaulting to xml.

This PR sets the lang prop in this instance to be html.

My only remaining question is if xml makes sense as the default or if the default should be html - but that question feels out of scope for this PR (and landing this PR won't break anything if we change the default to html in the future).

@open-craft-grove

Copy link
Copy Markdown

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove

Copy link
Copy Markdown

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@brian-smith-tcril
brian-smith-tcril merged commit 17e514f into openedx:master Jun 2, 2025
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Contributions Jun 2, 2025
@mariajgrimaldi

Copy link
Copy Markdown
Member

Thank you all! @tonybusa: can you help us backporting this into the release/teak branch? We'd really appreciate it!

@tonybusa

tonybusa commented Jun 2, 2025

Copy link
Copy Markdown
Contributor Author

Thank you all! @tonybusa: can you help us backporting this into the release/teak branch? We'd really appreciate it!

Hey @mariajgrimaldi, @Faraz32123 - should I backport this change and #1869 in the same PR?

If the answer is YES - here's the PR: #2065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-sandbox open-craft-grove should create a sandbox environment from this PR mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[UI Issue] <TC_Author_53>: <HTML button is broken>

9 participants