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: add lazy component #615

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

feat: add lazy component #615

wants to merge 5 commits into from

Conversation

mtt-artis
Copy link

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.

@lovasoa
Copy link
Collaborator

lovasoa commented Sep 22, 2024

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

Copy link
Author

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 ?

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)

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
Author

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.

@mtt-artis
Copy link
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 😉

select 'lazy' as component;

select
'/chart-example.sql?_sqlpage_embed' as embed,
Copy link
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.

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

@lovasoa
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.

@@ -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
Author

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 ?

sqlpage/sqlpage.js Outdated Show resolved Hide resolved
c.dispatchEvent(fragLoadedEvt);
})
function sqlpage_embed() {
for (const c of document.querySelectorAll("[data-embed]")) {
Copy link
Author

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants