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

Breaking while loop crashes tab #591

Closed
MM263 opened this issue Mar 12, 2019 · 11 comments
Closed

Breaking while loop crashes tab #591

MM263 opened this issue Mar 12, 2019 · 11 comments
Labels
kind: bug Something isn't working
Milestone

Comments

@MM263
Copy link

MM263 commented Mar 12, 2019

My Specs

Bug reproduced on MacOS 10.14.3, Chrome 72.0.3626.12, Latest Safari
Latest [email protected]


Expected Behaviour

Making endless animation when using while loop shouldn't crash the browser tab.

Works perfectly in CodeSandbox.


What happened instead?

Following this example I tried implementing animation that is playing non-stop when while loop is set to true. I discovered that breaking that while loop crashes browser tabs (Safari, Chrome) both in dev environment and with minified build (Terser). Here is repro repository with the same component as in CodeSandbox.

Also, I found that leaving react-spring docs open for an extended amount of time also crashes the tab, but I can't reproduce it reliably.


Possible leads

  1. The fact that it works in CodeSandbox makes me think that it is could be related to build tools, but I can't imagine how.

  2. I think that there is a possibility that I should somehow cancel an animation with the second cancel argument in async "to", but there are no examples in the docs. If the problem lies in me misunderstanding how async "to" works, maybe we could add this use case to the docs.

  3. Also, using set and stop functions with custom loop using setInterval might help, but I couldn't get them to work as of now, I'm going to try and update later.

  4. Heavy inline SVG animation crashes Chrome tab sometimes. This is, I think, mostly not applicable in our case because the same crash happens even if you animate divs. However, people could repro the same behaviour with SVG relatively recently.

@subhero24
Copy link

I have the same issue. This code crashes the browser (chrome and safari):

useSpring({
	from: { transform: 'rotate(0deg)' },
	to: async next => {
		while (1) {
			await next({ transform: 'rotate(720deg)' });
			await next({ transform: 'rotate(0deg)' });
		}
	},
});

It completes the first iteration of the while loop normally, and then hangs the browser.
I could also not replicate this in a CodeSandbox. So maybe two different instances of react-spring in one build might be the issue ...?

@MM263
Copy link
Author

MM263 commented Mar 13, 2019

@subhero24 I'm glad to know I'm not only one who has the problem.

I am not entirely sure what you mean by "two different instances", but in my repro repo there is only one useSpring in the whole app, so that shouldn't be the case

@subhero24
Copy link

@MM263 I'm using a dependency that also has a react-spring dependency. So I think the build would contain two versions of react-spring. I'm not convinced this is the issue, but I mentioned it just in case.
As you pointed to build tools, I am using parcel for the build.

@MM263
Copy link
Author

MM263 commented Mar 13, 2019

@subhero24 Got it, thanks for clarification!

I'm using webpack by the way, so maybe we ruled out build tools :)

@aleclarson
Copy link
Contributor

aleclarson commented Apr 1, 2019

Cannot reproduce with https://codesandbox.io/s/v6o7666onl

LMK if you can break that, or provide a repository that I can run locally 👍

@aleclarson aleclarson added the type: needs repro Needs minimal reproduction label Apr 1, 2019
@subhero24
Copy link

I wanted to dig deeper into the issue just now. But I can not reproduce the issue anymore. Sadly, I have no idea what fixed it ...

@subhero24
Copy link

I was finally able to reproduce the bug! Here is a codesandbox that reproduces the issue: https://codesandbox.io/s/l4wqoyox5l

A one-time setState causes react-spring to go into an infinite loop. If you disable the line setState (index.js:24) inside useEffect, the tab crashes.

I disabled the sandbox "Infinite Loop Protection" in sandbox.config.json to show the issue of the infinite loop.

@aleclarson aleclarson reopened this Apr 1, 2019
@aleclarson aleclarson added kind: bug Something isn't working and removed type: needs repro Needs minimal reproduction labels Apr 1, 2019
@aleclarson
Copy link
Contributor

This seems to be fixed in #632 👍

@aleclarson aleclarson mentioned this issue Apr 15, 2019
5 tasks
@aleclarson
Copy link
Contributor

You can use v9 like this now: yarn add react-spring@next

Let us know how it goes: #642

@aleclarson aleclarson added this to the v9.0.0 milestone Apr 23, 2019
@subhero24
Copy link

Tried the 9.0.0 beta today, and it fixes the issue for me. Thank you!

@Code47X
Copy link

Code47X commented Sep 3, 2019

Just ran into this issue. v9.0.0 fixed it for me as well. Thanks! 🎉

@pmndrs pmndrs locked as resolved and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants