fix(content): apply --offset-top and --offset-bottom values correctly #20790
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm run lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Issue Number: #20735
What is the new behavior?
In some cases,
ion-content
is rendered/hydrated before the root document element is hydrated. Because of https://github.com/ionic-team/ionic/blob/c15ae7cbf58065086816ca352c0a5ce981bb25b5/core/src/css/structure.scss#L25-L27 the root document element will havedisplay: none
, causing theion-content
to be hidden. This also means itsoffsetParent
will benull
and the element will have dimensions of 0x0. This is causing the--offset-top
and--offset-bottom
variables to not be set with the correct values.To remedy this, I have created a MutationObserver that watched for attribute changes on
document.documentElement
(usuallyhtml
). The callback will recalculate the offset variable and then remove the observer if the root document element has thehydrated
class applied.In the event that
ion-content
is hydrated after the root document element, we still have thethis.resize()
call incomponentDidLoad
. If the root document element is already hydrated, the MutationObserver will not be created.Does this introduce a breaking change?
Other information