Skip to content

Call rAF with window/global scope #820

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

Closed
wants to merge 1 commit into from
Closed

Conversation

peteromano
Copy link

@peteromano peteromano commented Sep 30, 2019

Chrome seems to break when invoking rAF stored as a referenced property of a different object other than the global scope.

For example: https://stackoverflow.com/questions/9677985/uncaught-typeerror-illegal-invocation-in-chrome

Error is below:

parallax.cjs.js:195 Uncaught TypeError: Illegal invocation
    at onScroll (parallax.cjs.js:195)
    at HTMLUnknownElement.callCallback (react-dom.development.js:348)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:398)
    at invokeGuardedCallback (react-dom.development.js:455)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:469)
    at executeDispatch (react-dom.development.js:601)
    at executeDispatchesInOrder (react-dom.development.js:623)
    at executeDispatchesAndRelease (react-dom.development.js:726)
    at executeDispatchesAndReleaseTopLevel (react-dom.development.js:734)
    at forEachAccumulated (react-dom.development.js:708)
  var onScroll = function onScroll(event) {
    if (!state.busy) {
      state.busy = true;
      state.current = event.target[getScrollType(horizontal)];
      globals.requestAnimationFrame(function () {    // <--- Should be invoked with `window` scope
        state.layers.forEach(function (layer) {
          return layer.setPosition(state.space, state.current);
        });
        state.busy = false;
      });
    }
  };

CC: @aleclarson

Chrome seems to break when invoking rAF stored as a referenced property of a different object other than the global scope.

For example: https://stackoverflow.com/questions/9677985/uncaught-typeerror-illegal-invocation-in-chrome

Error is below:

```
parallax.cjs.js:195 Uncaught TypeError: Illegal invocation
    at onScroll (parallax.cjs.js:195)
    at HTMLUnknownElement.callCallback (react-dom.development.js:348)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:398)
    at invokeGuardedCallback (react-dom.development.js:455)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:469)
    at executeDispatch (react-dom.development.js:601)
    at executeDispatchesInOrder (react-dom.development.js:623)
    at executeDispatchesAndRelease (react-dom.development.js:726)
    at executeDispatchesAndReleaseTopLevel (react-dom.development.js:734)
    at forEachAccumulated (react-dom.development.js:708)
```

```
  var onScroll = function onScroll(event) {
    if (!state.busy) {
      state.busy = true;
      state.current = event.target[getScrollType(horizontal)];
      globals.requestAnimationFrame(function () {
        state.layers.forEach(function (layer) {
          return layer.setPosition(state.space, state.current);
        });
        state.busy = false;
      });
    }
  };
```
aleclarson added a commit that referenced this pull request Sep 30, 2019
@peteromano
Copy link
Author

@aleclarson Can this get merged into v9 ahead of #808/#809 (today, if possible), if 808/9 will take a considerable amount of time longer to ship?

@aleclarson
Copy link
Contributor

Please try 9.0.0-canary.809.3.a66b280 first.

If that doesn't work for you, I can release a v9 canary with cba7e99.

@aleclarson aleclarson closed this Sep 30, 2019
@peteromano
Copy link
Author

👍 ty!

@peteromano
Copy link
Author

peteromano commented Sep 30, 2019

Tested; seems to be working correctly. In retrospect, for anyone else reading:

  1. Use 9.0.0-canary.809.3.a66b280 (or v9, upon v9 canary #808/feat: useTransition rewrite #809 merge),
  2. import 'react-spring'; (before importing add-ons),
  3. import {Parallax, ParallaxLayer} from '@react-spring/addons/parallax.cjs';.

aleclarson added a commit that referenced this pull request Oct 2, 2019
aleclarson added a commit that referenced this pull request Oct 3, 2019
aleclarson added a commit that referenced this pull request Oct 6, 2019
aleclarson added a commit that referenced this pull request May 3, 2020
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