-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: main
Are you sure you want to change the base?
Conversation
077f5f9
to
82a05a6
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
8d3ef65
to
c4be790
Compare
@@ -389,7 +391,7 @@ var CodeOceanEditor = { | |||
updateEditorModeToFileTypeID: function (editor, fileTypeID) { | |||
var newMode = 'ace/mode/text' | |||
|
|||
$.ajax(this.fileTypeURL + '/' + fileTypeID, { | |||
$.ajax(this.fileTypeURL() + '/' + fileTypeID, { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
There was a problem hiding this 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.
There was a problem hiding this 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).

c4be790
to
1062f2d
Compare
@@ -1,4 +1,7 @@ | |||
var CodeOceanEditor = { | |||
import * as Routes from 'generated/routes'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
1062f2d
to
5518e2b
Compare
JavaScript for RfCs, Flashes and the color mode can be moved without modifications. Relates to #3021
ddb6a43
to
721f80e
Compare
Code editor modules are moved and modularized for later removal from global scope. Relates to #3021
5518e2b
to
c60094e
Compare
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