GAUD-9445: only render loading backdrop when shown#6601
GAUD-9445: only render loading backdrop when shown#6601
Conversation
|
Thanks for the PR! 🎉 We've deployed an automatic preview for this PR - you can see your changes here:
Note The build needs to finish before your changes are deployed. |
| super(); | ||
| this.shown = false; | ||
| this._state = null; | ||
| this._state = 'hidden'; |
There was a problem hiding this comment.
There's a new default hidden state.
So the lifecycle now looks like:
hidden: nothing rendered, host isdisplay: noneshowing: host and loading spinner are rendered but haveopacity: 0shown: opacity is now set, fade-in animation startshiding: opacity is set back to0, fade-out animation startshidden: back to the beginning, nothing is rendered and host isdisplay: none
| updated(changedProperties) { | ||
| if (changedProperties.has('_state')) { | ||
| if (this._state === 'showing') { | ||
| setTimeout(() => this._state = 'shown', BACKDROP_DELAY_MS); |
There was a problem hiding this comment.
This is the trick/magic here, as we move the 800ms delay from the animation to a timeout. This allows things to render with no visible changes for 800ms, then start the fade-in.
There was a problem hiding this comment.
Oh cool- good idea 👀
One Q- does this get cancelled if the load takes less time than the delay? E.G. does it ever go hidden -> showing -> hidden -> shown and get stuck in that state?
There was a problem hiding this comment.
Looks like I can trigger that scenario if I adjust the load timing on the demo to 50ms from 5000ms:
Recording.2026-02-13.162017.mp4
Though I imagine that's a solvable problem- I'll try adding on a check in the timeout block?
There was a problem hiding this comment.
This patch prevents that issue afaict:
if (this._state === 'showing') {
setTimeout(() => {
if (this._state === 'showing') this._state = 'shown';
}, BACKDROP_DELAY_MS);
}
There was a problem hiding this comment.
Oh yeah good call! Yeah I think a check in the timeout block would work, just to make sure it's still in the state it expects.
There was a problem hiding this comment.
Ok that's fixed, good catch. I also needed to just hide immediately in #fade() if shown gets set to false while things are still showing.
661bb62 to
d35bf89
Compare
| <div class="backdrop" _state=${this._state} @transitionend=${this.#handleTransitionEnd} @transitioncancel=${this.#hide}></div> | ||
| <d2l-loading-spinner _state=${this._state} size="${this._state === null ? '0' : '50'}"></d2l-loading-spinner> | ||
| <div class="backdrop" @transitionend="${this.#handleTransitionEnd}" @transitioncancel="${this.#hide}"></div> | ||
| <d2l-loading-spinner></d2l-loading-spinner> |
There was a problem hiding this comment.
I also removed _state on the backdrop and spinner as we can just use a :host([_state="whatever"]) d2l-loading-spinner selector.
Size also isn't needed anymore since nothing renders at all when the state is hidden.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…hub.com/BrightspaceUI/core into GAUD-9445/backdrop-loading-improvements
| :host([_state="showing"]), | ||
| :host([_state="shown"]), | ||
| :host([_state="hiding"]) { | ||
| display: flex; |
There was a problem hiding this comment.
👀 CSS noob question- why are we setting this here?
There was a problem hiding this comment.
I see in the W3 schools docs that this uses a flexbox layout which aligns items in a row- but these are laid out more on top of each other 🤔
There was a problem hiding this comment.
Using flexbox is an alternate (and IMO better) way to center the d2l-loading-spinner horizontally, instead of width: 100%; height: 100% which results in it taking up 100% of the space. Which is... fine, but not what I would have expected.
There was a problem hiding this comment.
Ah I see, I assume that centers by default because you're using it in conjunction with justify-content:center?
There was a problem hiding this comment.
Yeah exactly. There are a few other ways... left: 50% + a transform: translate(-50%, -50%) but I like avoiding transform whenever possible.
duncanuszkay-d2l
left a comment
There was a problem hiding this comment.
The less rendering, the better 😸 Learned the hard way!
This change looks like an improvement to me, so I'll leave my ✅
When this feature shipped, there was an issue where the loading spinner was getting in the way even when the
backdrop-loadingwasn't used -- which is the case almost everywhere.This changes things around so that by default the backdrop will both be
display: noneand also rendernothing. Once it'sshown, then it'll render things and start the animations/spinner.That required some changes to timings, as you can't animate something that's
display: noneor not rendered! 😆