-
Notifications
You must be signed in to change notification settings - Fork 64
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
fix: make Tutor-MFE config compatible with React Router v6 #574
Conversation
As part of the React Router v5 -> v6 upgrade, history was no longer being passed in. This broke the Tutor deployment method of MFEs, which puts all the MFEs in a common server and uses different top-level dirs to separate them. The fix for this is to pass in an explicit basename to the Router.
9575d09
to
6f080b2
Compare
@brian-smith-tcril, @arbrandes: I'm not sure what needs to be done in terms of tests and version bumping here? |
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #574 +/- ##
==========================================
+ Coverage 83.17% 83.19% +0.01%
==========================================
Files 40 40
Lines 1070 1071 +1
Branches 195 195
==========================================
+ Hits 890 891 +1
Misses 168 168
Partials 12 12
☔ View full report in Codecov by Sentry. |
FYI @kdmccormick |
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.
Aside from one nit/suggestion, these changes LGTM. I tested using frontend-template-application's MFE on top of devstack with the following test cases:
PUBLIC_PATH
configured as/
.PUBLIC_PATH
configured as/testing
.PUBLIC_PATH
not configured.
All test cases seem to be working as expected.
src/initialize.js
Outdated
const configBasename = getPath(getConfig().PUBLIC_PATH); | ||
return configBasename.endsWith('/') ? configBasename.slice(0, -1) : configBasename; |
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.
Nit/Note: not all MFEs currently have a PUBLIC_PATH
configured (e.g., presumably MFEs not officially part of Tutor). That said, things seem to still work as expected in this case as getConfig().PUBLIC_PATH
falls back to /
if not provided.
In the case where getConfig().PUBLIC_PATH
is /
, this basename
function returns an empty string. This would force react-router's Router
component's basename
prop to fall back to its own /
instead.
While it seems to be fine as is, I'm wondering if we should be explicitly handle the fallback to /
on our own here without relying on the fallback within Router
itself? E.g.
export function basename() {
const configBasename = getPath(getConfig().PUBLIC_PATH);
if (configBasename === '/') {
return configBasename;
}
return configBasename.endsWith('/') ? configBasename.slice(0, -1) : configBasename;
}
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.
Do we need to do the /
stripping at all? Based on https://github.com/remix-run/react-router/blob/f9b3dbd9cbf513366c456b33d95227f42f36da63/packages/router/utils.ts#L1031-L1053
// We want to leave trailing slash behavior in the user's control, so if they // specify a basename with a trailing slash, we should support it
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 would avoid stripping the tail /
here, since:
- It's not necessary for react-router (as Brian S shows above)
- It goes beyond feature parity with what worked before the react-router-v6 upgrade
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.
@adamstankiewicz: I'll make it really explicit in that way, thank you.
@brian-smith-tcril: React Router wants to leave it in our control, but I think that we should be consistent and not have a mix of /library-authoring/
, /account
, /authn/
, etc. Our backend app config is using the ones without trailing slashes, so the current live URLs don't have trailing slashes. So even though I think that having slashes is actually the right thing to do from an academic perspective, I'd rather be standardized on what's already out there.
I do intend to make a separate PR to tutor-mfe
to fix how it writes this config, but I thought that for rollout/upgrade ease, we should force this behavior across MFEs.
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.
@arbrandes, @brian-smith-tcril: Okay, I want to make sure I'm not misunderstanding something.
Given the current state of tutor-mfe-generated config and the URLs we currently have, the code is broken without that stripping. Tutor MFE code will generate the PUBLIC_PATH as /library-authoring/
. Trying to load http://apps.local.overhang.io:3001/library-authoring
(no trailing slash) will cause an error because the route is not specified that way. The only reason this worked (edit: might have worked?) before was because React Router used to be more permissive about what it would accept here, and in v6 they've gotten more explicit.
I actually have no objection to removing the stripping behavior and relying on everyone getting the updated tutor-mfe generated config. I was just worried that this would complicate things when people are updating, especially if re-deployment doesn't happen all at once.
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've made the PR to tutor-mfe to fix the config (overhangio/tutor-mfe#154). I'll remove the slash stripping part from this PR.
5d57eec
to
64f3539
Compare
@brian-smith-tcril, @arbrandes: Modified to just take the config value as-is, and relying on overhangio/tutor-mfe#154 to make sure we're getting the right value. |
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.
Thanks again, Dave! Looks good to me!
Description:
As part of the React Router v5 -> v6 upgrade, history was no longer being passed in. This broke the Tutor deployment method of MFEs, which puts all the MFEs in a common server and uses different top-level dirs to separate them.
The fix for this is to pass in an explicit basename to the Router.
Merge checklist:
frontend-platform
. This can be done by runningnpm start
and opening http://localhost:8080.module.config.js
file infrontend-build
.fix
,feat
) and is appropriate for your code change. Consider whether your code is a breaking change, and modify your commit accordingly.Post merge: