Code Monkey home page Code Monkey logo

react-pts-canvas's People

Contributors

beewee22 avatar dependabot[bot] avatar flaming-codes avatar joserfelix avatar prkirby avatar tibotiber avatar usarneme avatar williamngan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-pts-canvas's Issues

Infinite recursion if using a tsup build

After upgrading to tsup build, using this react component will result in a "Maximum call stack" error.

Looks like the issue is related to babel, where "Super call in arrow function causing infinite recursion"
babel/babel#15148

For now, this component will use Pts v0.10.x instead of v0.11.x until we can find a solution to this.

Making sure a space is fully disposed when unmounting

Hi @williamngan,

This is a follow up to #16 for which I'll post a PR in a minute.

Zooming out from that specific issue, I'm wondering if there are other things that should be removed when unmounting: event listeners, bound methods, animation requests, others?. Maybe space should have a dispose method? This is to ensure that applications which open/close the canvas many times do not suffer bad performance.

I am motivated to make the PRs for this but might need your guidance to know where are potential performance issues / handlers leaks. Not sure if there is anything at all (do you know of a way to debug that easily?), but worth stopping to think about it I guess.

What do you think?

Also this might be better listed in the pts repo, let me know if you want to change that.

React hooks / functional components?

Is there any roadmap or interest in supporting useX-style / react hook functions with this?

Over the past year I've began using functional components more to control components. Though not quite sure whether or not PtsCanvas could be extrapolated to hooks yet.

React 18 support

Verify if React 18 will work as is, and then update package.json to use '>=' instead of '~' in React versioning.

Invalid use of useLayoutEffect in SSR-env

Description

When using react-pts-canvas in a setup w/ SSR-rendering (e.g. Next.js), the usage of useLayoutEffect causes an issue as the hook is only allowed to run on the client. Subsequently, a warning is logged to the console.

The line causing the issue is here.

Solution

useLayoutEffect should only be used on the client, therefore an isomorphic variant is required that runs safely on both client + server. Example of an existing package. As the change is basically a one-liner, I wouldn't propose to use a package but rather implement it directly.

I would be grateful to work on it.

Repo to reproduce

Screenshots

Description Image
Warning log Screenshot 2022-05-24 at 22 05 57

Play get called twice?

After fixing a replay issue, I found that maybePlay get called twice after a state change in the parent component.

Repro:

  1. run the example and click the Play/Stop button on top-left
  2. Edit maybePlay with console.log
const maybePlay = () => {
    const space = spaceRef.current
    if (!space) return
    if (play) {
      if (space.isPlaying) {
        space.resume()
        console.log('resume!')
      } else {
        space.replay() // if space has stopped, replay
        console.log('replay')
      }
    } else {
      space.pause(true)
      console.log('pause!')
    }
  }
  1. See that console.log get 'pause!' and 'resume!' on a single click

Resize event listener not cleared on unmount

Hi @williamngan, it seems that the listener for resize events is not removed when the component unmounts. The listener gets set in the main pts lib from this line:

this.space = new CanvasSpace( this.canvRef ).setup({
bgcolor: this.props.background,
resize: this.props.resize,
retina: this.props.retina

From there it ends up here in pts:

https://github.com/williamngan/pts/blob/fdb8fd52b8f9d45bfe6a77d2bccd0bda72f9d86b/src/Canvas.ts#L173-L180

I think we could add a componentWillUnmount lifecycle method that calls this.space.autoResize(false). Would that work?

But I also feel it would be better that pts handles this on its own by deregistering event handlers when the element is unmounted. I couldn't find anywhere that tracks unmounting though and not sure how to proceed.

Happy to try to code that but I might need some pointers ;).

I can re-open this in the pts repo if that's more suitable.

Performance issue

Hi @williamngan,

I've had some performance issue in my app which I narrowed down to the PtsCanvas component. To be precise, when this component gets re-rendered many times (e.g. from prop change, the CPU usage goes up to more than 90%).

I've checked and it seems to come from the call to play() L25 below:

componentDidUpdate() {
this._update();
}
_update() {
if (this.props.play) {
this.space.play();
} else {
this.space.playOnce(0);
}
if (this._touch !== this.props.touch) {
this._touch = this.props.touch;
this.space.bindMouse( this._touch ).bindTouch( this._touch );
}
}

I'm guessing play() should only be called if there was a change in props, not every time. Another way would be to make sure play doesn't cause this kind of performance issue in the ptsjs lib.

I can try to open a PR, but would rather get your opinion on this first.
โœŒ๏ธ

Async onStart method

Hi,

First i would like to thank you for this rly rly great library.

I have a small problem and maybe you can help me.
I would like to make multiple api calls in the onStart method but sadly the method is not async. How could i solve this ?

Best Regards
Thomas

3px space at the bottom

I've been having an issue where there are a 3-annoying-little-pixels space at the bottom between the container and the canvas. Just wanted to highlight that I got rid of it by adding lineHeight: 0 to the style prop. Not really an issue with the lib per se, but might be useful for others. Feel free to close ;)

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.