Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add lazy component #615

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

Draft
mtt-artis wants to merge 5 commits into sqlpage:main
base: main
Choose a base branch
Loading
from mtt-artis:lazy
Draft

feat: add lazy component #615

mtt-artis wants to merge 5 commits into sqlpage:main from mtt-artis:lazy

Conversation

@mtt-artis
Copy link
Contributor

@mtt-artis mtt-artis commented Sep 22, 2024

Hi 👋,

I'm working with some resource-intensive queries that take some time to execute, and the embed option on the card component works really well. However, I’d like to prevent layout shifts and avoid having cards nested inside other cards.

The lazy component follows a similar logic but provides an element you can style before it's replaced with the actual content.

Please feel free to make any changes, rename the component (coming from React/Solid, that's what comes naturally to me), or guide me in the right direction.

If you like this implementation, I'd be happy to add it to the documentation.

Copy link
Collaborator

lovasoa commented Sep 22, 2024
edited
Loading

Hello ! This sounds like a very useful component to add, and I'll be happy to integrate it. Thank you ! 😊

Could you please:

if (c.ariaBusy === "true") return;
c.ariaBusy = true;
const [source, params] = c.dataset.embed.split("?");
if (!source) return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you may want to log an error, but still continue with the other lazy elements on the page

mtt-artis reacted with thumbs up emoji
Copy link
Contributor Author

@mtt-artis mtt-artis Sep 22, 2024

Choose a reason for hiding this comment

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

my bad, rest of a forEach variant

Comment on lines 13 to 15
if (!search.has("_sqlpage_embed")) {
search.set("_sqlpage_embed", "true");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe just search.set("_sqlpage_embed", ""); without the if ?

mtt-artis reacted with thumbs up emoji
for (const c of document.querySelectorAll("[data-embed]")) {
if (c.ariaBusy === "true") return;
c.ariaBusy = true;
const [source, params] = c.dataset.embed.split("?");
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can parse the url correctly with new URL(c.dataset.embed, window.location.href)

mtt-artis reacted with thumbs up emoji
c.dispatchEvent(fragLoadedEvt);
})
function sqlpage_embed() {
for (const c of document.querySelectorAll("[data-embed]")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this should be done in parallel rather than sequentially ?

Copy link
Contributor Author

@mtt-artis mtt-artis Sep 22, 2024

Choose a reason for hiding this comment

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

I am not sure if I understand you.
We don't await the fetch so the loop does't wait the promise to be resolved to start the next element.

Copy link
Contributor Author

hi 👋,
Thanks for your comments

  • remove the indentation changes to make the code easier to review

could we invest for future change and make the indentation consistent across the file ?

I can add tests and documentation during the next WE if you don't mind 😉

lovasoa reacted with heart emoji

select 'lazy' as component;

select
'/chart-example.sql?_sqlpage_embed' as embed,
Copy link
Contributor Author

@mtt-artis mtt-artis Sep 22, 2024
edited
Loading

Choose a reason for hiding this comment

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

should we keep as embed or as lazy here ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think as embed is good

mtt-artis reacted with thumbs up emoji
Copy link
Collaborator

lovasoa commented Sep 22, 2024

Yes, we can set an indentation standard, but maybe after your PR? You are going to end up with large conflicts for nothing, otherwise. I need a clean diff in this PR to review it.

mtt-artis reacted with thumbs up emoji

@@ -0,0 +1,13 @@
<div class="{{default class "my-2"}}"{{~#if style}} style="{{style}}" {{/if~}}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

In all other components, class adds new classes without replacing the existing ones

Copy link
Contributor Author

@mtt-artis mtt-artis Sep 22, 2024

Choose a reason for hiding this comment

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

i know and i hesitate, this div is a light wrapper and i think user should be able to reset it easily if needed.

same for <div class="{{default class "card my-2"}}">. i add this default because most of the component are card.

should we just give no default and handle it like the style param ?

c.dispatchEvent(fragLoadedEvt);
})
function sqlpage_embed() {
for (const c of document.querySelectorAll("[data-embed]")) {
Copy link
Contributor Author

@mtt-artis mtt-artis Sep 22, 2024

Choose a reason for hiding this comment

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

is the query better ?
document.querySelectorAll("[data-embed]:not([aria-busy=true])")

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes it's better !

Co-authored-by: Ophir LOJKINE <contact@ophir.dev>
Copy link
Collaborator

lovasoa commented Oct 19, 2024

Hello ! Any news on this ? I think only docs and tests are missing, then we can merge !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lovasoa lovasoa lovasoa requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /