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

Added "Advanced Guides" page about cross-origin Errros #10457

Merged
merged 2 commits into from
Aug 14, 2017

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Aug 14, 2017

Follow-up for #10447; resolves #10441.

Follow-up items

Preview in the new docs site

screen shot 2017-08-14 at 11 23 13 am

@@ -54,6 +54,8 @@
title: Integrating with Other Libraries
- id: accessibility
title: Accessibility
- id: cross-origin-errors
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be in the table of contents? Normally we don't add items for warnings. Those who have them will read this by following a link, those who don't probably don't need to know this. Every item in TOC adds some extra mental overhead for people learning React.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question. I was on the fence about this. I'll remove it for now. 😄


### Webpack

Certain [Webpack `devtool` settings](https://webpack.js.org/configuration/devtool/) can cause cross-origin errors. We recommend using the `cheap-module-source-map` setting to avoid this problem.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I offered another way to phrase this in Quip, feel free to use that or combine. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That must have come in after I posted this. I'll use that wording.

@bvaughn bvaughn force-pushed the cross-origin-error-docs branch 2 times, most recently from 40adf03 to e188b47 Compare August 14, 2017 19:49
@bvaughn
Copy link
Contributor Author

bvaughn commented Aug 14, 2017

Suggested change was made!


If an error is thrown from a [different origin](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) the browser will mask its details and React will not be able to log the original error message. This is a security precaution taken by browsers to avoid leaking sensitive information.

If you trust the scripts you're running you can ask the browser to bypass the same-origin policy in a secure way. Doing this can help simplify the development/debugging process. Below are a some common causes of cross-origin errors and ways to address them.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed this before you put up the PR: You should always trust the scripts you're running. :) This isn't actually the relevant characteristic here I think. (More strictly, it's "if the scripts you're running trust you" but I don't think that's clearer.)

Can this be "If your server is set up to deliver scripts with the proper headers" or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper headers are listed below as 1 of the 2 possible causes.

Maybe something like this?

You can simplify the development/debugging process by ensuring that errors are thrown with a same-origin policy. Below are some common causes of cross-origin errors and ways to address them.

We can also always tweak this wording later.


Some JavaScript bundlers may wrap the application code with `eval` statements in development. For example Webpack will do so if the [`devtool` setting](https://webpack.js.org/configuration/devtool/) is any of the options containing the word "eval" (which includes the default setting).

If you use Webpack, we recommend using the `cheap-module-source-map` setting in development instead to avoid this problem.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a Chrome bug? Or intentional behavior?

Copy link
Contributor Author

@bvaughn bvaughn Aug 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncertain. Chrome was the only browser I tested that demonstrated this behavior- but it's also the most commonly-used browser.


### Webpack

Some JavaScript bundlers may wrap the application code with `eval` statements in development. For example Webpack will do so if the [`devtool` setting](https://webpack.js.org/configuration/devtool/) is any of the options containing the word "eval" (which includes the default setting).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it? My impression is that by default Webpack won't either generate source maps nor use evals.

Copy link
Contributor Author

@bvaughn bvaughn Aug 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I saw this behavior when I removed the devtool setting entirely. I also saw reference online about it defaulting to "eval" but looking at where I think it's set in their code, that doesn't seem to be the default.

I will confirm now.

Edit 1: It looks like if debug is on, they may default to eval-cheap-module-source-map. (I'm not at all familiar with this codebase so I'm not sure how these pieces fit together really.)

Edit 2: I'll just back down the wording here (for now) to be a little less broad. We can tweak it later as we learn more about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. I think most people won't have the debug field set (in my experience it's not commonly known, and I also can't find docs for it).

@bvaughn
Copy link
Contributor Author

bvaughn commented Aug 14, 2017

Thanks for the suggestions! 😁

I'm going to merge this and setup the fb.me link (since both are RC-blockers). We'll improve the wording over time.

@bvaughn bvaughn merged commit b4a3e3b into facebook:master Aug 14, 2017
@bvaughn bvaughn deleted the cross-origin-error-docs branch August 14, 2017 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cross-origin error passed to componentDidCatch incorrectly
4 participants