Skip to content

refactor: Move Sprocket JS files to Webpack (Part 2) #3030

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

arkirchner
Copy link
Contributor

@arkirchner arkirchner commented Jul 22, 2025

Code editor modules are moved with minimal changes.

The editor is tested in the exercise implimentaion page. Admin exercise page and the RfC page.

Relates to #3021

@arkirchner arkirchner self-assigned this Jul 22, 2025
@arkirchner arkirchner added the javascript Pull requests that update Javascript code label Jul 22, 2025
@arkirchner arkirchner force-pushed the ak/move_sprocket_assets_to_webpack_part_2 branch from 077f5f9 to 82a05a6 Compare July 22, 2025 12:54
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.08%. Comparing base (721f80e) to head (c60094e).

Additional details and impacted files
@@                            Coverage Diff                             @@
##           ak/move_sprocket_assets_to_webpack_part_1    #3030   +/-   ##
==========================================================================
  Coverage                                      70.08%   70.08%           
==========================================================================
  Files                                            215      215           
  Lines                                           6850     6850           
==========================================================================
  Hits                                            4801     4801           
  Misses                                          2049     2049           

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

@arkirchner arkirchner marked this pull request as ready for review July 22, 2025 13:16
@arkirchner arkirchner marked this pull request as draft July 22, 2025 13:33
@arkirchner arkirchner force-pushed the ak/move_sprocket_assets_to_webpack_part_2 branch 2 times, most recently from 8d3ef65 to c4be790 Compare July 22, 2025 15:00
@@ -389,7 +391,7 @@ var CodeOceanEditor = {
updateEditorModeToFileTypeID: function (editor, fileTypeID) {
var newMode = 'ace/mode/text'

$.ajax(this.fileTypeURL + '/' + fileTypeID, {
$.ajax(this.fileTypeURL() + '/' + fileTypeID, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Routes.js needs the page to be rendered before execution. Calling this on execution ensures the page is present.

@arkirchner arkirchner marked this pull request as ready for review July 22, 2025 15:11
Copy link

@ibrahimkonuk ibrahimkonuk left a comment

Choose a reason for hiding this comment

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

Looks good to me, but haven't tested locally

Copy link

@christophblessing christophblessing left a comment

Choose a reason for hiding this comment

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

What about the failing specs? Your changes seem not functional.

Copy link
Member

@MrSerth MrSerth left a comment

Choose a reason for hiding this comment

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

On my machine, core aspects of the application are broken, such as the navigation. In addition, errors are given on the console, which reminds me of #2953 (review).

Image

@arkirchner arkirchner marked this pull request as draft July 28, 2025 07:00
@arkirchner arkirchner force-pushed the ak/move_sprocket_assets_to_webpack_part_2 branch from c4be790 to 1062f2d Compare July 28, 2025 08:37
@@ -1,4 +1,7 @@
var CodeOceanEditor = {
import * as Routes from 'generated/routes';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not quite sure why Routes needs to be included here explicitly. I am a bit worried why this worked locally for me (now also failing for me).

We are setting Routes on the window in the application.js before requiring the editor.
https://github.com/openHPI/codeocean/blob/main/app/javascript/application.js#L77

This breaks my understanding of how JavaScript should work for me. Is Webpacker moving JS around?

Copy link

@christophblessing christophblessing Jul 28, 2025

Choose a reason for hiding this comment

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

I'm not very familiar with the code base. But from your description of the problem I would say that it's better to explicitly import the Routes in the all modules they need it.

Attaching something to the window leads to several problems like global namespace pollution, potential module system conflicts and challenges in maintainability (difficult to track for developers). If CodeOcean has a module system in place, we should also use it. Attaching objects to the global space should be avoided.

Choose a reason for hiding this comment

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

It could be a cached local build or browser script cache which is why it worked initially. I just read in this article here that it might be a scoping issue and explicitly importing looks like the best way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@christophblessing
I agree that it would be better to implicitly import everything. In this transition, this is a bit difficult because this would mean a large code change. I want to first move the JavaScript sprockets and then refactor them with more and more implicit imports.

@ibrahimkonuk
Thank you for linking this article. I will look deeper into how webpack orders the objects.

I want to avoid some on of solution. Implicitly importing Routes here and using the window version in other places might work but will cause difficult issues down the line. I will keep this as a draft while researching.

@arkirchner arkirchner force-pushed the ak/move_sprocket_assets_to_webpack_part_2 branch from 1062f2d to 5518e2b Compare July 28, 2025 09:23
JavaScript for RfCs, Flashes and the color mode can be moved without
modifications.

Relates to #3021
@arkirchner arkirchner force-pushed the ak/move_sprocket_assets_to_webpack_part_1 branch from ddb6a43 to 721f80e Compare July 30, 2025 11:50
Code editor modules are moved and modularized for later removal from
global scope.

Relates to #3021
@arkirchner arkirchner force-pushed the ak/move_sprocket_assets_to_webpack_part_2 branch from 5518e2b to c60094e Compare July 30, 2025 12:30
Base automatically changed from ak/move_sprocket_assets_to_webpack_part_1 to main August 1, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants