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

Add click-to-open support for build errors #3100

Merged
merged 9 commits into from
Oct 6, 2017

Conversation

tharakawj
Copy link
Contributor

@tharakawj tharakawj commented Sep 10, 2017

Resolves #2805

This a basic implementation of "click to open in editor" feature for build(compile time) errors and We can improve it based on the feedback coming from the community.

Currently, it only supports Babel syntax errors and ESLint errors. What are the other common or known error types that we can consider here?

Also, please note that this includes a refactoring to the programming interface of the error overlay and it will break any project that uses the package separately without CRA.

@@ -25,6 +25,18 @@ var launchEditorEndpoint = require('./launchEditorEndpoint');
var formatWebpackMessages = require('./formatWebpackMessages');
var ErrorOverlay = require('react-error-overlay');

ErrorOverlay.listenToOpenInEditor(function OpenInEditor({
Copy link
Contributor

@Timer Timer Sep 10, 2017

Choose a reason for hiding this comment

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

Why a separate function?

Can we just put this back under ErrorOverlay.startReportingRuntimeErrors under the prop launchEditor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ErrorOverlay.startReportingRuntimeErrors and its parameters are specific to runtime errors. But listenToOpenInEditor will trigger the listener for both runtime and build errors. So isn't that less intuitive to put OpenInEditor under ErrorOverlay.startReportingRuntimeErrors?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, this makes sense. Thanks!

} = this.props.frame;
// Keep this in sync with react-error-overlay/middleware.js
Copy link
Contributor

@Timer Timer Sep 10, 2017

Choose a reason for hiding this comment

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

This comment was lost when the code was moved.
I assume it might need updating, or is it not relevant anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an updated comment.

@Timer
Copy link
Contributor

Timer commented Sep 10, 2017

I wonder why Travis CI is failing. 🤔

@TryingToImprove
Copy link

Uncaught [TypeError: ErrorOverlay.listenToOpenInEditor is not a function]

@Timer
Copy link
Contributor

Timer commented Sep 10, 2017

@TryingToImprove yes, but the function is present and it works on AppVeyor.

I'm interested in why it's failing on Travis specifically, e.g. due to an npm bug, etc.

@tharakawj
Copy link
Contributor Author

I experience the same for kitchensink in my local development environment. Looking further I found it uses bundle.js with old react-error-overlay/index.js. Probably your #3102 will fix this.

@Timer
Copy link
Contributor

Timer commented Sep 11, 2017

Can you try it with my PR? Feel free to merge it if it resolves it -- I'm in bed. 😄

@tharakawj
Copy link
Contributor Author

I'll try it in the evening.

@tharakawj tharakawj force-pushed the build-error-open-editor branch from 5765617 to 8fe1724 Compare September 11, 2017 16:13
@tharakawj
Copy link
Contributor Author

Rebased with the latest master. No idea why it's still failing. 😕

@viankakrisna
Copy link
Contributor

@tharakawj i think it's npm 5 bug...

@viankakrisna
Copy link
Contributor

see #3105

@tharakawj
Copy link
Contributor Author

tharakawj commented Sep 11, 2017

I see. I'll rebase and try after #3107

@Timer
Copy link
Contributor

Timer commented Sep 12, 2017

#3107 has been merged.

@tharakawj tharakawj force-pushed the build-error-open-editor branch from 8fe1724 to 9064ca9 Compare September 12, 2017 16:53
@Timer
Copy link
Contributor

Timer commented Sep 13, 2017

Yikes -- looks like CI is still failing. Do you have time to look into this or maybe I could find some time to?

@tharakawj
Copy link
Contributor Author

Yeah! I won't be able to look into this until the weekend. Please have a look if possible.

@tharakawj
Copy link
Contributor Author

Finally, I think I found the actual reason why CI is failing and it will be fixed with #3139. But I'm still curious how it doesn't affect to AppVeyor build.

@tharakawj tharakawj force-pushed the build-error-open-editor branch from 9064ca9 to eba9f53 Compare September 16, 2017 15:50
@tharakawj
Copy link
Contributor Author

Ready to review! 😎

@react-scripts-dangerous

Hello! I'm a bot that helps facilitate testing pull requests.

Your pull request (commit eba9f53caac2452d8c91687784a66a757fcaf07f) has been released on npm for testing purposes.

npm i react-scripts-dangerous@1.0.14-eba9f53.0
# or
yarn add react-scripts-dangerous@1.0.14-eba9f53.0
# or
create-react-app --scripts-version=react-scripts-dangerous@1.0.14-eba9f53.0 folder/

Note that the package has not been reviewed or vetted by the maintainers. Only install it at your own risk!

Thanks for your contribution!

@@ -25,6 +25,16 @@ var launchEditorEndpoint = require('./launchEditorEndpoint');
var formatWebpackMessages = require('./formatWebpackMessages');
var ErrorOverlay = require('react-error-overlay');

ErrorOverlay.listenToOpenInEditor(function OpenInEditor(errorLocation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, listenToOpenInEditor is a little ambiguous. e.g. can you listen with more than one function, or is this action reversible?
Questions people might have in mind if they're thinking of an EventEmitter (listeners/observers).

What about setEditorCallback or setEditorHandler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point. Just I couldn't think of any better name than this. Let's go with setEditorHandler.

let currentBuildError: null | string = null;
let currentRuntimeErrorRecords: Array<ErrorRecord> = [];
let currentRuntimeErrorOptions: null | RuntimeReportingOptions = null;
let stopListeningToRuntimeErrors: null | (() => void) = null;

export function listenToOpenInEditor(listener: OpenInEditorListener) {
Copy link
Contributor

@Timer Timer Sep 17, 2017

Choose a reason for hiding this comment

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

If this is renamed to setEditorCallback/setEditorHandler, we could make this accept OpenInEditorListener | null so it can be switched off by sending null.

@@ -168,7 +157,7 @@ class StackFrame extends Component<Props, State> {
}
}

const canOpenInEditor = this.getEndpointUrl() !== null;
const canOpenInEditor = this.getErrorLocation() !== null;
Copy link
Contributor

@Timer Timer Sep 17, 2017

Choose a reason for hiding this comment

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

Shouldn't this also still consider if overlay has a callback set? We don't want to style the text as clickable if it's a noop (if my understanding is correct here).

Can we do away with the openInEditorListener and openInEditor indirection and simply pass what the user has sent all the way through to the component so we can check if it's null?

I'd imagine we could just call update() when the callback is set to ensure props are updated in components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think we should. I'll fix this.

}

function openInEditor(errorLoc: ErrorLocation) {
if (typeof openInEditorListener === 'function') {
Copy link
Contributor

@Timer Timer Sep 17, 2017

Choose a reason for hiding this comment

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

This is the indirection I'm referencing below. Alternatively, we could add a warning, e.g. "You attempted to open a file in your editor but no handler was set".

@Timer Timer added this to the 1.0.15 milestone Sep 29, 2017
@Timer
Copy link
Contributor

Timer commented Oct 4, 2017

I'd like to release this PR in conjunction with #3142 so that we don't have to bump the major version of react-error-overlay twice.

@tharakawj tharakawj force-pushed the build-error-open-editor branch from eba9f53 to a0b3566 Compare October 4, 2017 17:48
@tharakawj
Copy link
Contributor Author

@Timer Updated the PR. Here I had check errLoc twice to avoid a flow error. Any better way to do it? Otherwise, if everything is ok, you can merge this and cut the release.

@react-scripts-dangerous
Copy link

Hello! I'm a bot that helps facilitate testing pull requests.

Your pull request (commit ae18e55) has been released on npm for testing purposes.

npm i react-scripts-dangerous@1.0.15-ae18e55.0
# or
yarn add react-scripts-dangerous@1.0.15-ae18e55.0
# or
create-react-app --scripts-version=react-scripts-dangerous@1.0.15-ae18e55.0 folder/

Note that the package has not been reviewed or vetted by the maintainers. Only install it at your own risk!

Thanks for your contribution!

@Timer
Copy link
Contributor

Timer commented Oct 4, 2017

Oh, I hope I didn't come off as wanting to release ASAP, I just meant to have it in before the next release.

I'll take a look at this soon. 😄

@Timer
Copy link
Contributor

Timer commented Oct 5, 2017

What happens if you change const canOpenInEditor = errLoc !== null && editorHandler !== null; to const canOpenInEditor = errLoc != null && editorHandler != null;?

Since errLoc is ?ErrorLocation it may be null or undefined, so you only checked if it was null.

Alternatively, we can make parseCompileError return ErrorLocation | null.
We don't want a maybe type here (?ErrorLocation).

@tharakawj
Copy link
Contributor Author

Unfortunately, neither of these approaches seem to work. Apparently, flow can't refine the type when we check null/undefined through another variable. Try this snippet if you want to play around it.

@Timer
Copy link
Contributor

Timer commented Oct 5, 2017

Interesting, it seems flow cannot flow follow those cases; not a problem! I have nothing against the double check.

@Timer Timer merged commit 00ed100 into facebook:master Oct 6, 2017
@Timer
Copy link
Contributor

Timer commented Oct 6, 2017

:shipit:

matart15 pushed a commit to matart15/create-react-app that referenced this pull request Oct 19, 2017
…react-app

* 'master' of https://github.com/facebookincubator/create-react-app:
  Update README.md
  Fix dead link to Jest "expect" docs (facebook#3289)
  Use production React version for bundled overlay (facebook#3267)
  Add warning when using `react-error-overlay` in production (facebook#3264)
  Add external links to deployment services (facebook#3265)
  `react-error-overlay` has no dependencies now (facebook#3263)
  Add click-to-open support for build errors (facebook#3100)
  Update style-loader and disable inclusion of its HMR code in builds (facebook#3236)
  Update url-loader to 0.6.2 for mime ReDoS vuln (facebook#3246)
@gaearon gaearon mentioned this pull request Oct 30, 2017
suutari-ai referenced this pull request in andersinno/create-react-app-ai Jan 25, 2018
…pescript

* 'master' of https://github.com/wmonk/create-react-app-typescript: (265 commits)
  fix typo in changelog
  Update README For 2.13.0
  v2.13.0
  Remove tslint-loader from prod build (again)
  Include TypeScript as devDependency in boilerplate output
  Documented how to define custom module formats for the TypeScript compiler so that you can import images and other files (references wmonk#172)
  v2.12.0
  Update README For 2.12.0
  Update typescript to 2.6.2
  v2.11.0
  Update changelog for 2.11.0
  Fixed problem with tsconfig.json baseUrl and paths
  Update createJestConfig.js
  Update changelog for 2.10.0
  v2.10.0
  Readd transformIgnorePatterns
  Update react-dev-utils
  Update package.json dependencies
  Readd Missing raf Package
  Update JestConfig Creation
  Fix
  Fix Missing Variable
  Fix package.json
  Merge pull request wmonk#204 from StefanSchoof/patch-1
  Merge pull request wmonk#201 from StefanSchoof/patch-1
  Merge pull request wmonk#199 from DorianGrey/master
  Merge pull request wmonk#165 from johnnyreilly/master
  Publish
  Add 1.0.17 changelog (#3402)
  Use new WebpackDevServer option (#3401)
  Fix grammar in README (#3394)
  Add link to VS Code troubleshooting guide (#3399)
  Update VS Code debug configuration (#3400)
  Update README.md (#3392)
  Publish
  Reorder publishing instructions
  Changelog for 1.0.16 (#3376)
  Update favicon description (#3374)
  Changelog for 1.0.15 (#3357)
  Replace template literal; fixes #3367 (#3368)
  CLI@1.4.2
  Publish
  Add preflight CWD check for npm (#3355)
  Stop using `npm link` in tests (#3345)
  Fix for add .gitattributes file #3080 (#3122)
  Mention that start_url needs to be "." for client side routing
  start using npm-run-all to build scss and js (#2957)
  Updating the Service Worker opt-out documentation (#3108)
  Remove an useless negation in registerServiceWorker.js (#3150)
  Remove output.path from dev webpack config (#3158)
  Add `.mjs` support (#3239)
  Add documentation for Enzyme 3 integration (#3286)
  Make uglify work in Safari 10.0 - fixes #3280 (#3281)
  Fix favicon sizes value in manifest (#3287)
  Bump dependencies (#3342)
  recommend react-snap; react-snapshot isn't upgraded for React 16 (#3328)
  Update appveyor.cleanup-cache.txt
  Polyfill rAF in test environment (#3340)
  Use React 16 in development
  Use a simpler string replacement for the overlay
  Clarify the npm precompilation advice
  --no-edit
  Update `eslint-plugin-react` (#3146)
  Add jest coverage configuration docs (#3279)
  Update link to Jest Expect docs (#3303)
  Update README.md
  Fix dead link to Jest "expect" docs (#3289)
  v2.8.0
  Use production React version for bundled overlay (#3267)
  Add warning when using `react-error-overlay` in production (#3264)
  Add external links to deployment services (#3265)
  `react-error-overlay` has no dependencies now (#3263)
  Add click-to-open support for build errors (#3100)
  Update style-loader and disable inclusion of its HMR code in builds (#3236)
  Update url-loader to 0.6.2 for mime ReDoS vuln (#3246)
  Make error overlay to run in the context of the iframe (#3142)
  Upgrade to typescript 2.5.3
  Fix Windows compatibility (#3232)
  Fix package management link in README (#3227)
  Watch for changes in `src/**/node_modules` (#3230)
  More spec compliant HTML template (#2914)
  Minor change to highlight dev proxy behaviour (#3075)
  Correct manual proxy documentation (#3185)
  Improve grammar in README (#3211)
  Publish
  Fix license comments
  Changelog for 1.0.14
  BSD+Patents -> MIT (#3189)
  Add link to active CSS modules discussion (#3163)
  Update webpack-dev-server to 2.8.2 (#3157)
  Part of class fields to stage 3 (#2908)
  Update unclear wording in webpack config docs (#3160)
  Display pid in already running message (#3131)
  Link local react-error-overlay package in kitchensink test
  Resolved issue #2971 (#2989)
  Revert "run npm 5.4.0 in CI (#3026)" (#3107)
  Updated react-error-overlay to latest Flow (0.54.0) (#3065)
  Auto-detect running editor on Linux for error overlay (#3077)
  Clean target directory before compiling overlay (#3102)
  Rerun prettier and pin version (#3058)
  ...
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants