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

[MWPW-161098] Links conversion localization support #3120

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

robert-bogos
Copy link
Contributor

@robert-bogos robert-bogos requested a review from a team October 31, 2024 09:26
@robert-bogos robert-bogos self-assigned this Oct 31, 2024
Copy link
Contributor

aem-code-sync bot commented Oct 31, 2024

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.34%. Comparing base (8f0adc1) to head (7d8cd8e).
Report is 28 commits behind head on stage.

Additional details and impacted files
@@           Coverage Diff           @@
##            stage    #3120   +/-   ##
=======================================
  Coverage   96.34%   96.34%           
=======================================
  Files         245      245           
  Lines       56316    56322    +6     
=======================================
+ Hits        54256    54264    +8     
+ Misses       2060     2058    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -647,21 +647,27 @@ const decorateCopyLink = (a, evt) => {
};

export function convertStageLinks({ anchors, config, hostname, href }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I lack the context, hence the question:
No matter if this is done before or after the localization, we'd just swap out the host, no? Since localization is part of the path - we aren't touching it and this should already be done somewhere from the milo links conversion 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, this does look a bit more convoluted than needed, at least at a first glance. The localizeLink method should handle all the complexities of handling the locale prefix. There are use-cases we need to consider, such as #_dnt links, which should not be translated. That even has a originHostName parameter, which might come in handy when trying to switch up origins.

Copy link
Contributor Author

@robert-bogos robert-bogos Oct 31, 2024

Choose a reason for hiding this comment

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

These changes were necessary for use cases where different consumers share the same domain but are differentiated by path (e.g., bacom and bacom blog).

For example, without the updates in this PR, if a consumer sets the following mapping:

  '^https://some.consumer': {
    '^https://business.adobe.com(?!/blog)': 'https://business.stage.adobe.com',
    '^https://business.adobe.com/blog': 'https://main--bacom-blog--adobecom.hlx.page',
  },

they would expect that, on https://some.consumer, business.adobe.com would convert to business.stage.adobe.com and business.adobe.com/blog to main--bacom-blog--adobecom.hlx.page.

This works when localization isn’t involved, but on https://some.consumer/de, both business.adobe.com/de/blog and business.adobe.com/de would convert to business.stage.adobe.com/de, which is wrong.

My solution is to remove the localization from the path, do the conversions and then reattach the localization.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds a little confusing, would it not be already possible to add the locale part to the regex as an optional parameter? 🤔

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 was my initial thought, but you'll end up losing the locale part when doing the conversion with String.replace()

Copy link
Contributor

@vhargrave vhargrave Nov 5, 2024

Choose a reason for hiding this comment

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

@robert-bogos I feel super bad for writing this now, but still curious what you think. What if we made this a config option instead? Every consumer can decide for themselves if they want their stage links converted with an option like
stageLinkTransformation: on

Then this could be opt in, you'd have way simpler code, and we'd be sending less bytes to consumers. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

cc: @mokimo @narcis-radu @overmyheadandbody if you want to chime in too :)

Copy link
Contributor

@mokimo mokimo Nov 5, 2024

Choose a reason for hiding this comment

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

@vhargrave this is already opt in, albeit the config is a bit more involved to get this running rather than just on. We had discussed things back and forth a lot, but settled on this and had a few iterations of it.

This feature is not as trivial as one might think, has a lot of corner cases and can vary from each consumer to the next 😬

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks for explaining and sending this discussion @mokimo 🙌
I didn't realize the requirements were so broad and that config option certainly won't cover it lol.

Copy link
Contributor

@mokimo mokimo left a comment

Choose a reason for hiding this comment

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

My initial feeling tells me, there should be a simpler solution, then again - I'm not the one who conducted the due diligence and found all the corner cases.

Thanks for being diligent and answering the questions and doing the education work and providing context!

@narcis-radu narcis-radu requested a review from vhargrave November 5, 2024 10:05
Copy link
Contributor

github-actions bot commented Nov 6, 2024

Reminder to set the Ready for Stage label - to queue this to get merged to stage & production.

@NadiiaSokolova NadiiaSokolova self-assigned this Nov 6, 2024
Copy link

@NadiiaSokolova NadiiaSokolova left a comment

Choose a reason for hiding this comment

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

Verified. Ready for Stage.
Testing details https://jira.corp.adobe.com/browse/MWPW-161098

@milo-pr-merge
Copy link
Contributor

milo-pr-merge bot commented Nov 6, 2024

Skipped 3120: "[MWPW-161098] Links conversion localization support" due to file "libs/utils/utils.js" overlap. Merging will be attempted in the next batch

@milo-pr-merge milo-pr-merge bot merged commit 948a940 into adobecom:stage Nov 7, 2024
19 checks passed
@milo-pr-merge milo-pr-merge bot mentioned this pull request Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants