-
Notifications
You must be signed in to change notification settings - Fork 50.5k
[Flight] Warn once if eval is disabled in dev environment
#35661
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
base: main
Are you sure you want to change the base?
[Flight] Warn once if eval is disabled in dev environment
#35661
Conversation
328e3c3 to
41e269c
Compare
3a8565c to
b4f7dca
Compare
0fa91a0 to
876bf8c
Compare
| // A warning would be noise if you used Flight without Components and don't encounter | ||
| // errors. We're warning eagerly so that you configure your environment accordingly | ||
| // before you encounter an error. | ||
| checkEvalAvailabilityOnceDev(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be in ReactFlightReplyClient.js where eval is used? Looks like ReactFlightReplyServer.js does not use eval.
| } catch { | ||
| console.error( | ||
| 'eval() is not supported in this environment. ' + | ||
| 'If this page was served with a `Content-Security-Policy` header, ' + | ||
| 'make sure that `unsafe-eval` is included. ' + | ||
| 'React requires eval() in development mode for various debugging features ' + | ||
| 'like reconstructing callstacks from a different environment.\n' + | ||
| 'React will never use eval() in production mode', | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If eval throws for reasons other than being unavailable, those errors will be swallowed.
| } catch { | |
| console.error( | |
| 'eval() is not supported in this environment. ' + | |
| 'If this page was served with a `Content-Security-Policy` header, ' + | |
| 'make sure that `unsafe-eval` is included. ' + | |
| 'React requires eval() in development mode for various debugging features ' + | |
| 'like reconstructing callstacks from a different environment.\n' + | |
| 'React will never use eval() in production mode', | |
| ); | |
| } | |
| } catch (error) { | |
| console.error( | |
| 'eval() is not supported in this environment. ' + | |
| 'If this page was served with a `Content-Security-Policy` header, ' + | |
| 'make sure that `unsafe-eval` is included. ' + | |
| 'React requires eval() in development mode for various debugging features ' + | |
| 'like reconstructing callstacks from a different environment.\n' + | |
| 'React will never use eval() in production mode', | |
| ,error | |
| ); | |
| } |
Summary
Follow-up to #35650
React uses
evalin development for Server Components and Server Functions to reconstruct callstacks from different environments.evalcan be a legitimate security concern for production environments. It's oftentimes disabled e.g. in browsers viaContent-Security-Policy.If
evalis disabled in development, those debugging features stop working. Without this change no warning was issued. Now we issue a warning with remedies depending on the environment.For browsers, the CSP header needs to be adjusted. In Node.js,
--disallow-code-generation-from-stringsshould not be used. In other environments (e.g. Bun), we don't have a tailored message since those environments don't have a dedicated API to disableeval.If there are legit concerns about disabling
evalin development this warning could be considered noise and we should revisit.Note that we always warn once you use React Server or React Action APIs even though you may not need to reconstruct a callstack (e.g. no Components used or errors transported). I suspect this to be a rare use cases. Though being prepared for potential errors, isn't the worst idea.
How did you test this change?