aem-core-wcm-components
aem-core-wcm-components copied to clipboard
[LinkHandler] Refactor / improve `LinkHandler`
Feature Request
Is your feature request related to a problem? Please describe. This issue is not a bug fix - just optimizations / improvements:
- The current
LinkHandlermodel does not implement an interface. #1818 requests that an interface be made public; however, until it is made public a non-exported interface should exist so that when it is time to make the interface public it does not require a major refactoring to accomplish. - The link handler model implementation contains some unnecessary code duplication that can be eliminated.
- The link handler model implementation - in some cases - computes fall-back values before knowing that they are required, thus incurring the overhead even when they are not needed.
- The link handler model implementation returns the raw type
Linkwhere that generic type should be parameterized asLink<Page>. The ambiguity in the API does not provide any benefit and the weakness of the interface (once exposed) will lead to confusion by clients trying to make use of it, and to possible breaking-changes that cannot be expressed via the API. - The test coverage for the
LinkHandlerImplis incomplete - it does not test linking to redirect pages / chains of redirect pages with/without shadowing. - A silent bug exists in the
LinkHandlerImpltests that results in the incorrect resource being injected into the test models - this bug only surfaces when testing testing link redirect shadowing.
Describe the solution you'd like
- Create an interface
LinkHandlerand rename the current link handler model implementation toLinkHandlerImpl. The new interface should not (at this time) be exported from the bundle (see #1818 - Refactor
LinkHandlerImplto reduce code duplication - Refactor
LinkHanlderImplto only compute fall-back value if needed. - Change the
LinkHandlerto returnLink<Page>instead of the raw typeLink- do not update any exported model interfaces that already use the raw type so that this change is non-breaking. - Improve test coverage prior to any refactoring of the link handler implementation so as to be able to reliably assert no break in functionality due to the refactoring / rewriting.
- Correct the testing bug and ensure that the resource injected into the link model is the link resource, and not the page content resource.
Are there alternatives? No
Documentation N/A - no functional change
@adobe export issue to Jira project SITES
:white_check_mark: Jira issue SITES-5541 is successfully created for this GitHub issue.