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

[Feature]: Support lazy load <InView /> #1071

Open
manudeli opened this issue Jul 11, 2024 · 8 comments
Open

[Feature]: Support lazy load <InView /> #1071

manudeli opened this issue Jul 11, 2024 · 8 comments
Assignees
Milestone

Comments

@manudeli
Copy link
Member

manudeli commented Jul 11, 2024

Package Scope

etc

Description

@suspensive/intersection to trigger fetch on view inside of window

Possible Solution

const posts = useSuspenseQuery(postsQueryOptions(...))

return posts.map((post) => (
    <Intersection fallback={<Skeleton />}>
      <Suspense fallback={<Skeleton />}>
        <SuspenseQuery {postQueryOptions(post.id)}>
          {(post) => <Post {...post} />}
        </SuspenseQuery>
      </Suspense>
    </Intersection>
  )
)

etc.

No response

@manudeli
Copy link
Member Author

manudeli commented Jul 11, 2024

const posts = useSuspenseQuery(postsQueryOptions(...))

return posts.map((post) => (
  <Suspense intersection fallback={({ intersectionRef }) => <Skeleton ref={intersectionRef} />}>
    <SuspenseQuery {postQueryOptions(post.id)}>
      {(post) => <Post {...post} />}
    </SuspenseQuery>
  </Suspense>
  )
)

@gwansikk @kangju2000 @bigsaigon333
This could be new intersection prop of Suspense to lazy load??

@manudeli manudeli changed the title [Feature]: @suspensive/intersection [Feature]: intersection prop of <Suspense/> Jul 11, 2024
@manudeli manudeli changed the title [Feature]: intersection prop of <Suspense/> [Feature]: Support lazy load by intersection prop of <Suspense/> Jul 11, 2024
@gwansikk
Copy link
Collaborator

gwansikk commented Jul 11, 2024

const posts = useSuspenseQuery(postsQueryOptions(...))

return posts.map((post) => (
  <Suspense intersection fallback={({ intersectionRef }) => <Skeleton ref={intersectionRef} />}>
    <SuspenseQuery {postQueryOptions(post.id)}>
      {(post) => <Post {...post} />}
    </SuspenseQuery>
  </Suspense>
  )
)

@gwansikk @kangju2000 @bigsaigon333
This could be new intersection prop of Suspense to lazy load??

Oh, that's a great idea! It seems useful for gradually loading the necessary data for users through lazy loading

@minsoo-web
Copy link
Member

minsoo-web commented Jul 11, 2024

How about this interface ?

const posts = useSuspenseQuery(postsQueryOptions(...))

<Suspense when="intersectionObserve"></Suspense>
<Suspense when="render"></Suspense> // default
<Suspense triggerBy="intersectionObserve"></Suspense>
<Suspense triggerBy="render"></Suspense>  // default

I think the intersection prop is too much of an abstraction.
What you want to do is determine the moment that creates the suspense, so I'm thinking of something like a trigger or a when.

@minsoo-web
Copy link
Member

However, I think Intersection Observe should have more options.

For example,

rootMargin
thresholds

I thought, "How do I set these options?"

@minsoo-web
Copy link
Member

const posts = useSuspenseQuery({
  ...otherOptions,
  observeRef: ref
})

return <div ref={ref}

How about this approach:
if we get a ref, we'll treat it like an enable, and it'll work then, so the user doesn't have to know about the intersection observe api.

@manudeli
Copy link
Member Author

We should support react-native and web at once too!

@manudeli
Copy link
Member Author

manudeli commented Jul 11, 2024

<InView>
  {(trigger) => (
    <div ref={trigger.ref}>
      <Suspense enabled={trigger.isInView} fallback={<Spinner/>}>
        <SuspensQuery />
      </Suspense>
    </div>
  )}
</InView>

@manudeli
Copy link
Member Author

manudeli commented Jul 15, 2024

<InView>
  {(target) => (
    <div ref={target.ref}>
      <Suspense fallback={<Spinner/>}>
        {target.isInView ? <SuspensQuery/> : <SuspenseAllTime/>}
      </Suspense>
    </div>
  )}
</InView>

@manudeli manudeli added this to the v3 milestone Jul 18, 2024
manudeli added a commit that referenced this issue Jul 30, 2024
related with #1093 #1109 #1072 #1071

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

I want to support isomorphic `<InView/>`, `<FadeIn/>` for react-dom and
react-native at once. This pull request is start for it

- @suspenisve/react-native 
- @suspenisve/react-dom

![Jul-27-2024
05-05-21-min](https://github.com/user-attachments/assets/ce5bc8bd-9a96-42b3-b954-672dacbc0dec)

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
@manudeli manudeli self-assigned this Aug 1, 2024
@manudeli manudeli changed the title [Feature]: Support lazy load by intersection prop of <Suspense/> [Feature]: Support lazy load <InView /> Aug 1, 2024
manudeli added a commit that referenced this issue Aug 3, 2024
related with #1093 #1109 #1072 #1071

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

I want to support isomorphic `<InView/>`, `<FadeIn/>` for react-dom and
react-native at once. This pull request is start for it

- @suspenisve/react-native 
- @suspenisve/react-dom

![Jul-27-2024
05-05-21-min](https://github.com/user-attachments/assets/ce5bc8bd-9a96-42b3-b954-672dacbc0dec)

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
manudeli added a commit that referenced this issue Aug 3, 2024
related with #1093 #1109 #1072 #1071

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

I want to support isomorphic `<InView/>`, `<FadeIn/>` for react-dom and
react-native at once. This pull request is start for it

- @suspenisve/react-native 
- @suspenisve/react-dom

![Jul-27-2024
05-05-21-min](https://github.com/user-attachments/assets/ce5bc8bd-9a96-42b3-b954-672dacbc0dec)

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
manudeli added a commit that referenced this issue Aug 3, 2024
related with #1093 #1109 #1072 #1071

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

I want to support isomorphic `<InView/>`, `<FadeIn/>` for react-dom and
react-native at once. This pull request is start for it

- @suspenisve/react-native 
- @suspenisve/react-dom

![Jul-27-2024
05-05-21-min](https://github.com/user-attachments/assets/ce5bc8bd-9a96-42b3-b954-672dacbc0dec)

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
manudeli added a commit that referenced this issue Aug 3, 2024
related with #1093 #1109 #1072 #1071

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

I want to support isomorphic `<InView/>`, `<FadeIn/>` for react-dom and
react-native at once. This pull request is start for it

- @suspenisve/react-native 
- @suspenisve/react-dom

![Jul-27-2024
05-05-21-min](https://github.com/user-attachments/assets/ce5bc8bd-9a96-42b3-b954-672dacbc0dec)

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
manudeli added a commit that referenced this issue Sep 4, 2024
related with #1071

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

---------

Co-authored-by: Hyeonjae Lee <[email protected]>
Co-authored-by: Jun <[email protected]>
Co-authored-by: GwanSik Kim <[email protected]>
Co-authored-by: 김동희 <[email protected]>
Co-authored-by: Juhyeok Kang <[email protected]>
Co-authored-by: 김석진(poki) <[email protected]>
manudeli added a commit that referenced this issue Sep 4, 2024
related with #1071

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

---------

Co-authored-by: Hyeonjae Lee <[email protected]>
Co-authored-by: Jun <[email protected]>
Co-authored-by: GwanSik Kim <[email protected]>
Co-authored-by: 김동희 <[email protected]>
Co-authored-by: Juhyeok Kang <[email protected]>
Co-authored-by: 김석진(poki) <[email protected]>
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

No branches or pull requests

3 participants