Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

setImmediate() is a non-standard function #11

Closed
benpptung opened this issue Sep 7, 2017 · 6 comments
Closed

setImmediate() is a non-standard function #11

benpptung opened this issue Sep 7, 2017 · 6 comments

Comments

@benpptung
Copy link

Hi...got an Reference Error today, and found this is because setImmedaite() got called in componentWillReceiveProps(). can you fix it, I really like react-block-ui :)

@TheSharpieOne
Copy link
Collaborator

TheSharpieOne commented Sep 7, 2017

Eh, I figured that thing would be a thing by now (and I thought it was seeing how nodejs has it which I thought meant chrome did as well), but it looks like Chrome and Firefox don't like it for various "reasons" (very longs issue threads...). It is a standard, just an unofficial one which looks like will it never make it pass the editor's draft phase.
We use drafts all of the time (though usually working drafts) and depend on polyfills and transforms to allow us to use them.
Also, if you are using react, you are already including a polyfill for setImmediate via: setimmediate <- fbjs <- react

That being said, I'm going to make it so setImmediate doesn't need to be defined. ((window.setImmediate || setTimeout)(() => this.topFocus && this.topFocus.focus()); will probably work best)

@benpptung
Copy link
Author

I am using react, but I don't use the polyfill, I guess this is why I got that error. :)
Thank you for your reply, I've solved it already.

@TheSharpieOne
Copy link
Collaborator

I am not 100% sure how you are not using the polyfill since it is included with react via react's dependencies. Maybe treeshaking is removing it?

TheSharpieOne added a commit that referenced this issue Sep 7, 2017
@benpptung
Copy link
Author

I've been looking into React's code, and React doc website https://facebook.github.io/react/docs/hello-world.html, and I think React doesn't include setImmediate, because

  1. If we open the browser's console, type typeof setImmediate on the React website, it is undefined. It means no setImmediate exist in global, even React exist.

  2. And it seems React doesn't require setImmediate from fbjs to attach it to global.

So, you can find setImmediate in the global scope? ...mmm ... weird :)

@TheSharpieOne
Copy link
Collaborator

TheSharpieOne commented Sep 7, 2017

I have never used react with UMD imports and script tags like that, it appears they have a special build which limits the things they import from fbjs probably to help minimize the size. https://github.com/facebook/react/blob/2fa38ac1cce658ce799a162e65fcf782187c8802/scripts/rollup/modules.js#L188-L196

@benpptung
Copy link
Author

Yes ... :) I am still using require, and using browserify to bundle react.

so, if we cannot guarantee setImmediate() exist in global scope, I suggest to use setTimeout({fn}, 0), which should always works across browsers and server-rendering.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants