-
Notifications
You must be signed in to change notification settings - Fork 174
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
Add check if modules are same domain #226
Add check if modules are same domain #226
Conversation
core/src/services/routing.js
Outdated
} | ||
return true; | ||
}; | ||
|
||
const getDomainFromUrl = url => { |
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.
We should be able to detect multiple SPAs under one domain, i.e:
https://example.com/foo/
<-- root of one SPA
https://example.com/bar/
<-- root of another SPA
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 guess we do not have a concept / configuration option for that, since you would be currently only able to detect hash based SPAs, path based are undetectable by only the url. In my opinion this is a followup feature, which requires grooming.
c15ddfb
to
1d0e0e7
Compare
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.
Tested using tractor module:
{
label: 'Tractors',
pathSegment: 'tractors',
viewUrl: 'http://localhost:8080',
keepSelectedForChildren: true,
viewGroup : 'tractors',
children : [
{
label: 'tractor',
pathSegment: ':id',
viewUrl: 'http://localhost:8080/:id',
context: {
projectId
}
}
]
}
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.
Please see my comments
@@ -98,11 +98,29 @@ export const isNotSameDomain = (config, component) => { | |||
componentData.previousNodeValues.viewUrl | |||
); | |||
const nextUrl = getUrlWithoutHash(componentData.viewUrl); | |||
return previousUrl != nextUrl; |
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 suggest refactoring this code to a version where we have less returns, to make the code easier to understand and change in the future if needed. Here my suggestion:
export const isNotSameDomain = (config, component) => {
if (config.iframe) {
const componentData = component.get();
const previousUrl = getUrlWithoutHash(
componentData.previousNodeValues.viewUrl
);
const nextUrl = getUrlWithoutHash(componentData.viewUrl);
if (previousUrl === nextUrl) {
return false;
}
const previousUrlOrigin = getLocation(previousUrl);
const nextUrlOrigin = getLocation(nextUrl);
if (previousUrlOrigin === nextUrlOrigin) {
const previousViewGroup = componentData.previousNodeValues.viewGroup;
const nextViewGroup = componentData.viewGroup;
if (previousViewGroup && nextViewGroup && previousViewGroup === nextViewGroup) {
return false;
}
}
}
return true;
};
So we only return false if we detect we are in the same domain, otherwise code execution will come to the last line of the function and return true.
Also split the if..else
block to initialise some variables only if we need it. I executed the unit tests and they are still passing.
docs/navigation-configuration.md
Outdated
@@ -244,7 +246,7 @@ The node parameters are as follows: | |||
- **keepSelectedForChildren** focuses the navigation on its current hierarchy, omitting the display of children. | |||
- **loadingIndicator.enabled** shows a loading indicator when switching between micro front-ends. If you have a fast micro front-end, you can disable this feature to prevent flickering of the loading indicator. This parameter is enabled by default. | |||
- **loadingIndicator.hideAutomatically** disables the automatic hiding of the loading indicator once the micro front-end is loaded. It is only considered if the loading indicator is enabled. It does not apply if the loading indicator is activated manually with the `LuigiClient.uxManager().showLoadingIndicator()` function. If the loading indicator is enabled and automatic hiding is disabled, use `LuigiClient.uxManager().hideLoadingIndicator()` to hide it manually in your micro front-end during the startup. This parameter is enabled by default. | |||
|
|||
- **viewGroup** defines a group of views in the same domain sharing a common security context, which allows for example frame re-using for better performance. |
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.
There is a space too much in 'common security'
core/src/services/routing.js
Outdated
return node.viewGroup; | ||
} else if (node.parent) { | ||
return findViewGroup(node.parent); | ||
} else return; |
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.
else return
would not be needed, since javascript does implicitly that already
@@ -98,11 +98,29 @@ export const isNotSameDomain = (config, component) => { | |||
componentData.previousNodeValues.viewUrl | |||
); | |||
const nextUrl = getUrlWithoutHash(componentData.viewUrl); | |||
return previousUrl != nextUrl; |
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.
IMHO isNotSameDomain
isn't anymore a valid name for the function. My proposal is isNotSameViewGroup
. Or as it is a Luigi internal function, we could change the returns and how we use it and rename it to isSameViewGroup
. In general I find functions with negation more difficult to understand.
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 will refactor the function so it doesn't have negation, but I don't like the isSameViewGroup
nam, because in hash routing we don't have viewGroups. Maybe something more like isSameApplication
, isSameIFrame
?
@@ -797,6 +797,45 @@ describe('Routing', () => { | |||
previousNodeValues: { viewUrl: config.iframe.src } | |||
}); | |||
assert.isTrue(routing.isNotSameDomain(config, component)); | |||
|
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 rather split this test in several tests, and have all under a describe('FUNCTION NAME', () => {})
block.
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.
This would make also much easier to understand what each assertion is testing
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.
LGTM after the changes performed.
I would specify in the description of the 2 tests cases for viewGroups "same domain", e.g.:
should return XXX if views have same domain and XXX viewGroups
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.
Once comment :)
Co-Authored-By: dariadomagala <[email protected]>
…into same-domain-modules
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.
Added one more comment
Co-Authored-By: dariadomagala <[email protected]>
…into same-domain-modules
Add check if modules are same domain
Description
Changes proposed in this pull request:
Related issue(s)