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

Migrate Web Apps to RequireJS #34271

Merged
merged 94 commits into from
Apr 24, 2024
Merged

Migrate Web Apps to RequireJS #34271

merged 94 commits into from
Apr 24, 2024

Conversation

orangejenny
Copy link
Contributor

@orangejenny orangejenny commented Mar 12, 2024

Technical Summary

Does what the title says.

I'd recommend reviewing by commit. This is big, but most commits follow a similar pattern.

FAQ on RequireJS migration

This still isn't done?

Nope. Web apps, app manager, and reports still use script tags 🎶 like it's 1999 🎶

But RequireJS is deprecated.

Yep. This is still a step forward, since it makes all of the js dependencies in web apps explicit, which any modern module approach will expect. It is also a valuable endeavor to move our js dependency infrastructure to use modern tooling, but I am not blocking this work on that.

I'm now getting errors when I deploy to staging code that uses certain normal modern syntax like spread syntax and optional chaining.

Yep. This is the sad result of requirejs depending on a version of uglify that depends on an old version of esprima. See here. At least, I'm certain that's the problem with the spread syntax and suspect it's the same for optional chaining (EDIT: looks like it is). In third party libraries that are already minified, we can work around this by using empty: to skip optimization. For our own code, in theory we should be able to use babel-requirejs to work around it, but full disclosure I have not gotten that working and have been reduced to removing a small amount of that kind of code rather than blocking this migration on that problem.

Safety Assurance

Safety story

High risk. I'll coordinate with USH on testing and deploy timing.

Automated test coverage

Some. All web apps js tests are relevant here, but their coverage isn't that high.

QA Plan

Web apps UI regression: https://dimagi.atlassian.net/browse/QA-6193

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

Copy link
Contributor

@MartinRiese MartinRiese left a comment

Choose a reason for hiding this comment

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

Got to 76b6fe8. Waiting for a response so I don't make stuff unnecessarily.

Copy link
Contributor

@MartinRiese MartinRiese left a comment

Choose a reason for hiding this comment

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

Got to a9f8b0b

'backbone.marionette',
'cloudcare/js/formplayer/app',
'cloudcare/js/formplayer/utils/utils',
'bootstrap-switch/dist/js/bootstrap-switch', // bootstrapSwitch
Copy link
Contributor

Choose a reason for hiding this comment

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

So in this case what brought the bootstrap-switch dependency in before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That one is a jquery plugin, so it adds an attribute to jquery rather than its own global, so ESLint doesn't notice it.

@@ -109,7 +109,7 @@ <h3><%- displayText ? displayText : "" %></h3>
<div class="page-header menu-header">
<h1 class="page-title"><%- title %></h1>
</div>
<div class="<% if (environment === hqImport("cloudcare/js/formplayer/constants").PREVIEW_APP_ENVIRONMENT) { %>container<% } %>">
<div class="<% if (isAppPreview) { %>container<% } %>">
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you say in general that it is best practice to rely on variable instead of function calls/imports inside the templates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, definitely

_,
Marionette,
moment,
DOMPurify,
Copy link
Contributor

Choose a reason for hiding this comment

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

DOMPurify does not seem to be used in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, fixed in 3460c5b

Copy link
Contributor

@MartinRiese MartinRiese 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. The second half of my review might have been less focused :/

'cloudcare/js/formplayer/users/controller',
'cloudcare/js/formplayer/users/models',
'marionette.approuter/lib/marionette.approuter.min', // for Marionette.AppRouter
'cloudcare/js/formplayer/sessions/api', // for getSession
Copy link
Contributor

Choose a reason for hiding this comment

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

was resolving conflict on staging and noticed, is this needed? I think getSession is defined within router.js

Copy link
Contributor Author

@orangejenny orangejenny Mar 18, 2024

Choose a reason for hiding this comment

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

This is about the getSession channel request that's inside the getSession function (this), because the reply for that is defined in sessions/api. (Check out the commit comment on 04eb525.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I always thought just importing where the channel is defined cloudcare/js/formplayer/app was enough. Thanks for explaining

@orangejenny orangejenny added QA Passed and removed awaiting QA QA in progress. Do not merge labels Apr 24, 2024
@orangejenny orangejenny removed the Open for review: do not merge A work in progress label Apr 24, 2024
@orangejenny orangejenny merged commit 2fac97b into master Apr 24, 2024
13 checks passed
@orangejenny orangejenny deleted the jls/web-apps-requirejs branch April 24, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA Passed Risk: High Change affects files that have been flagged as high risk. Risk: Medium Change affects files that have been flagged as medium risk.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants