Git Product home page Git Product logo

Comments (7)

kwasimensah avatar kwasimensah commented on June 11, 2024

Furthermore Caurosel's onLoaderVisible can call onFetch again, which seems like it might be able to cause a parallel set of fetches to start (the calls to this.setState look a little iffy since it can be updated asynchronously and you're not explicitly the state in functions where it's blessed to be resolved).

from giphy-js.

giannif avatar giannif commented on June 11, 2024

@kwasimensah thanks for reporting this, you're seeing this in the React Carousel? It might require this fix that I just made to the grid. I'll take a look when I'm back in the office tomorrow

from giphy-js.

kwasimensah avatar kwasimensah commented on June 11, 2024

Yup, this is with Carousel

from giphy-js.

giannif avatar giannif commented on June 11, 2024

@kwasimensah I released a 1.0.6 version of @giphy/react-components, this should only trigger the paginator when the end of the carousel that has the loader element is on the screen. When the loader element goes off the screen, fetching should stop.

This is the approach we've been using for quite a bit on giphy.com with our grid, and in our web extensions and it should be solid.

Not sure exactly how it went so crazy in your implementation, but my bug fix tweaks the initial state, which when set to fetch on mount, I've seen the bug you're reporting when the browser isn't in the active tab.

If you're still seeing the issue, maybe compare to our codesandbox implementation: https://codesandbox.io/s/giphyreact-components-hbmcf?file=/src/index.tsx

Or provide more details 👍

from giphy-js.

kwasimensah avatar kwasimensah commented on June 11, 2024

Sandbox at https://codesandbox.io/s/giphyreact-components-td1qo?file=/src/index.tsx. If I make the searchTerm the key of the component it reloads as you type. But put in the term "hello world" and open the Chrome Dev console and you can see all the requests to giphy being made.

I think we need a hook in componentWillUnmount to tell the carousel to stop fetching.

from giphy-js.

giannif avatar giannif commented on June 11, 2024

@kwasimensah can you debounce your input? I'm going to investigate this, because it shouldn't happen regardless, but here is a codesandbox with a debounced input that works:
https://codesandbox.io/s/giphyreact-components-search-example-0yrur?file=/src/index.tsx

from giphy-js.

giannif avatar giannif commented on June 11, 2024

@kwasimensah I removed the need for the debounce in version 1.0.7. Should have tested without the debounce, my bad. Still good practice to have it though, to limit network requests while the user types.

I added an unmounted instance variable to check when componentWillUnmount so we don't setState after we unmount which triggered the loop

from giphy-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.