-
Notifications
You must be signed in to change notification settings - Fork 24.7k
[JS] Remove the global document
variable
#1473
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
Comments
document
variabledocument
variable
Can you send a pull request to remove the line that adds it? It's in InitializeJavascript js file |
@vjeux sure I will look into this. |
(We'll probably want to set it to |
@vjeux @spicyj I dug around for a while - we don't set GLOBAL or window.document anywhere, even in InitializeJavaScriptAppEngine.js I tried running If you try in the chrome or safari console to run the code: window.document = undefined;
window.document; You will see that window.document still returns the document. The better solution would not to override |
We really don't want a |
@jaredly I heard you were thinking about a new executor. There are a handful of issues like this one that could be closed by moving away from Chrome =) |
@oveddan I understand. Still annoying. :) |
Maybe we could run in a web worker instead of the main js thread when debugging in chrome. This way we won't have document. Not sure how the debugging experience is though |
@vjeux After your comment - I just confirmed that: If we wanted to have it run in the debugger from a web worker, it would need to be done for safari too. I feel like this would adversely effect the debugging experience. Also it would probably have issues should people want to use karma, or any other browser-based tester, to run tests. |
Can't we just change |
@jaredly It's not defined in the JSC executor, so we don't want it available when debugging either, for consistency. React isn't the only one who sniffs this. As one example, jQuery behaves differently depending on whether the |
Cool. I'd say let's try a webworker then -- debugging in chrome is pretty well supported (don't know about safari) |
JSC executer environment, where there is no global.document, make the chrome debugger run the javascript inside a web worker. This fixes facebook#1473 Some issues: - Ideally the websocket could be open inside the worker and communicated directly with it, but one of the messages requires access to localStorage, which is not accessable from within a worker. So the socket is still loaded from the webpage itself, and messages that the worker should handle are forwarded to it. - The worker does not have access to the global window object. In a worker, the global scope is a DedicatedWorkerGlobalScope and can be accessed via `self`
@spicyj On second look - the React tab is now gone from chrome when running the code in a worker, and using the debugger. Any suggestion on how to get it back? |
Yeah... That's probably going to be difficult with the current devtools.
|
Just as a side note if someone stumbles upon this issue. Debugging socket.io with chrome dev tools open is apparently impossible impossible at the moment. It'll throw up the document.createElement is undefined even though a successful connection can be made. It works perfectly fine and connects with chrome debugging off. |
seems like #1632 is in limbo. Is this still an issue? If so should that PR go through or is a different approach needed? |
…e the global document. Summary: To make the chrome debugger environment consisten with the JSC executer environment, where there is no `window.document`, make the chrome debugger run the javascript inside a web worker. This fixes facebook#1473 Closes facebook#1632 Reviewed By: @martinbigio Differential Revision: D2471710 Pulled By: @vjeux
Having a global
document
variable without implementing all of its methods causes interop issues with other libraries that expect the global document to have those methods, if it exists.This occurs, for example, when trying to require
jquery
, and it sees a global document and attempts to callcreateElement
on it. Use case and explaination of issue can be seen here.According to @vjeux
Therefore it seems the best solution would be to not attach the
react-native
specific document to global.The text was updated successfully, but these errors were encountered: