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

feat: visual-diff wait for async elements #17

Merged
merged 8 commits into from
Jun 13, 2023

Conversation

dlockhart
Copy link
Member

Small improvement to the fixture method which allows components to define an optional getLoadingComplete() method (similar to getUpdateComplete()) and fixture will wait for it to resolve before proceeding.

@dlockhart dlockhart requested a review from a team as a code owner June 12, 2023 21:14

const update = elem?.updateComplete;
if (typeof update === 'object' && Promise.resolve(update) === update) {
await update;
await nextFrame();
}

if (opts.awaitLoadingComplete && typeof elem?.getLoadingComplete === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the potential use cases for not wanting to wait for getLoadingComplete, if it exists? To vdiff skeletons?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that was the only use case I could think of, which is why I defaulted this to ON.

render() {
return html`<slot></slot>`;
}
async getLoadingComplete() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is kinda outside the scope of this PR, but worth bring up because I believe James might be starting on the skeleton group loading stuff soon - do you envision this being the same piece that could be used for the grouped skeletons, to tell the parent "I'm done loading and awaiting confirmation to turn off my skeleton". Or by all HM components in general, to indicate they're done?

Or do you see this as mostly a test/vdiff thing, and those will use cases will look more like the async container stuff?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good question, these things are definitely related.

The mechanism as it's used here is more of a 1-time thing that the tests wait for, whereas theoretically the skeleton stuff could go from loading -> ready and then back to loading, in which case the skeleton container and all the items in it should likely go back into skeleton mode.

For that reason my mind went more to the subscriber stuff for the skeletons. This also doesn't need to be set in stone -- once we figure out what works for the skeleton collection we can try this out with it and also try out visual-diff in some hypermedia repos and then adjust as necessary.

test/browser/fixture.test.js Outdated Show resolved Hide resolved
src/browser/fixture.js Outdated Show resolved Hide resolved
src/browser/fixture.js Outdated Show resolved Hide resolved
test/browser/fixture.test.js Outdated Show resolved Hide resolved
@dlockhart dlockhart merged commit 7d76f21 into main Jun 13, 2023
@dlockhart dlockhart deleted the dlockhart/async-components branch June 13, 2023 21:13
@ghost
Copy link

ghost commented Jun 13, 2023

🎉 This PR is included in version 0.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost ghost added the released label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants