Skip to content

Conversation

@marslanabdulrauf
Copy link
Contributor

@marslanabdulrauf marslanabdulrauf commented Nov 26, 2025

Related Ticket:

#2668
https://github.com/mitodl/hq/issues/9166#event-20756793537 (MIT Internal)

Description

This PR updates replaceStaticWithAsset function to not update non-asset static file path e.g;
/static/filename.ext is path for assets(file) while /static/images/filename.ext is standalone file path that don't need to be converted into assets url (/asset-v1:...)

Testing instructions

Follow the instructions from #2668 description, just skip the 1st point, don't disable replaceStaticWithAsset function.

Best Practices Checklist

We're trying to move away from some deprecated patterns in this codebase. Please
check if your PR meets these recommendations before asking for a review:

  • Any new files are using TypeScript (.ts, .tsx).
  • Avoid propTypes and defaultProps in any new or modified code.
  • Tests should use the helpers in src/testUtils.tsx (specifically initializeMocks)
  • Do not add new fields to the Redux state/store. Use React Context to share state among multiple components.
  • Use React Query to load data from REST APIs. See any apiHooks.ts in this repo for examples.
  • All new i18n messages in messages.ts files have a description for translators to use.
  • Avoid using ../ in import paths. To import from parent folders, use @src, e.g. import { initializeMocks } from '@src/testUtils'; instead of from '../../../../testUtils'

@openedx-webhooks
Copy link

openedx-webhooks commented Nov 26, 2025

Thanks for the pull request, @marslanabdulrauf!

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.


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.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 26, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Nov 26, 2025
@marslanabdulrauf marslanabdulrauf force-pushed the marslan/2668-9166-static-src-conversion branch from 47ad753 to a15ea7c Compare November 26, 2025 09:24
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.86%. Comparing base (ef36156) to head (bfe4b85).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2702   +/-   ##
=======================================
  Coverage   94.85%   94.86%           
=======================================
  Files        1232     1233    +1     
  Lines       27899    27941   +42     
  Branches     6316     6354   +38     
=======================================
+ Hits        26464    26506   +42     
  Misses       1364     1364           
  Partials       71       71           

☔ 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.

@marslanabdulrauf marslanabdulrauf marked this pull request as ready for review November 26, 2025 11:31
Comment on lines +125 to +126
// Check if this is a direct /static/filename.ext pattern (should be converted)
// vs /static/images/filename.ext pattern (should NOT be converted)
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, I think it is possible to have files in "Files & Uploads" for a course that have subdirectories, but it's rare, so I think this is a reasonable compromise for how to implement this. It is extremely unfortunate that our convention for specifying course assets as /static/foo.ext is in the same namespace as actual system-wide static files like /static/images/placeholder-faculty.png.

An alternative solution would be to move the placeholder-faculty image somewhere else, so it's served with a completely different URL or even changed into an inline SVG. Then we probably wouldn't need to worry about other usages of /static/ and can just assume they're all course assets. I'm wondering if you think that's a cleaner solution?

If we stick with this approach, I do think it would be good to add a couple more lines to the comment here to explain why we're not converting images with subfolders (because even though they may be course assets they're more likely to be some example images that are in Django's static folder).

CC @ormsbee who has more knowledge than me about static assets and their paths.

Copy link
Contributor Author

@marslanabdulrauf marslanabdulrauf Dec 1, 2025

Choose a reason for hiding this comment

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

An alternative solution would be to move the placeholder-faculty image somewhere else, so it's served with a completely different URL or even changed into an inline SVG. Then we probably wouldn't need to worry about other usages of /static/ and can just assume they're all course assets. I'm wondering if you think that's a cleaner solution?

We have a number of static assets under cms > images, lms > images, and common > images. From what I can tell, we are actively using two of the “placeholder” images:

  1. placeholder-faculty.png
  2. placeholder-image.png

If that's the full set, then yes, in theory we could move these to a separate folder outside of /static/ without much friction.
However, since images are conventionally served from static paths, it might be more appropriate to leave them where they are. @ormsbee would have better historical context on whether moving these makes sense.

If we stick with this approach, I do think it would be good to add a couple more lines to the comment here to explain why we're not converting images with subfolders (because even though they may be course assets they're more likely to be some example images that are in Django's static folder).

I'll add more detail to the comment 👍

Just to clarify: we’re not excluding all subfolders, only the images/ subfolder.

@bradenmacdonald
Copy link
Contributor

bradenmacdonald commented Nov 26, 2025

When I use the testing steps from #2668, this fix is only sort of working. When I load the page, it still shows "You've made some changes", and one of the images (using a studio URL like /static/example.jpg) is broken until I click somewhere in the editor. Then it appears suddenly. It's also changing the HTML from /static/... to /asset-v1:... which seems wrong to me, but the Text editor is doing that too, so we can consider that out of scope for now. (Edit: this actually seems fine - the Text editor does the same thing, and it seems that there is some code elsewhere that is updating these asset-v1: URLs when a course is re-run or exported and re-imported).

@marslanabdulrauf
Copy link
Contributor Author

Thanks @bradenmacdonald for the review.

I have added extra comments and fixed the issue where images are only updated when we click anywhere in the editor.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Dec 3, 2025
@bradenmacdonald
Copy link
Contributor

Thanks @marslanabdulrauf. I was just hoping to get some input from @ormsbee or other people before moving this forward.

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

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: In Eng Review

Development

Successfully merging this pull request may close these issues.

3 participants