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

feat: open editor when clicking error on overlay #4587

Merged
merged 2 commits into from Oct 12, 2022

Conversation

malcolm-kee
Copy link
Contributor

@malcolm-kee malcolm-kee commented Sep 27, 2022

  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

Motivation / Use-Case

This PR make webpack-dev-server open editor when user clicks on the error message on overlay.

Part of #3689.

Breaking Changes

Additional Info

  • New endpoint "/webpack-dev-server/open-editor" is added on the dev server which the client would calls using fetch.
  • Right now I assume moduleIdentifier from the stats.errors is the file name, but I not sure if that assumption is correct.
  • Use launch-editor to open editor (it is based on react-dev-utils of Create React App, and is being used by Vite as well).
  • For webpack 4 the logic does not work because there is no moduleIdentifier, but I assume that is not a dealbreaker.

@codecov
Copy link

codecov bot commented Sep 27, 2022

Codecov Report

Base: 91.96% // Head: 91.99% // Increases project coverage by +0.02% 🎉

Coverage data is based on head (b597b7a) compared to base (bce65af).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4587      +/-   ##
==========================================
+ Coverage   91.96%   91.99%   +0.02%     
==========================================
  Files          16       16              
  Lines        1655     1661       +6     
  Branches      622      623       +1     
==========================================
+ Hits         1522     1528       +6     
  Misses        122      122              
  Partials       11       11              
Impacted Files Coverage Δ
lib/Server.js 93.67% <100.00%> (+0.03%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

}
}

module.exports = launchEditor;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe there is a package for this? Also can we add unit tests for this?

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've installed launch-editor package, which apparently is extracted from react-dev-utils. It's also used by Vite as well.

lib/Server.js Outdated
@@ -2033,6 +2034,25 @@ class Server {
}
);

/** @type {import("express").Application} */
(app).get(
Copy link
Member

Choose a reason for hiding this comment

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

Let's add e2e test for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, it's added!

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Looks good, we need to test it to avoid problems, also maybe we have a package for launching (just question)?


/**
* @param {Parameters<import('puppeteer').Page['emulate']>[0]} config
* @returns {Promise<RunBrowserResult>}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additional typing to improve intellisense while writing tests.


if (typeof fileName === "string") {
// @ts-ignore
const launchEditor = require("launch-editor");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

require lazily to make mock possible.

@@ -203,6 +203,16 @@ function show(type, messages, trustedTypesPolicyName) {
typeElement.innerText = header;
applyStyle(typeElement, msgTypeStyle);

if (message.moduleIdentifier) {
applyStyle(typeElement, { cursor: "pointer" });
typeElement.dataset.canOpen = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is hook for e2e test. If there is other preferred convention, let me know!

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Sorry for delay, it looks good, @snitin315 Can you review this too?

Copy link
Member

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks ⭐

@alexander-akait alexander-akait merged commit efb2cec into webpack:master Oct 12, 2022
@alexander-akait
Copy link
Member

@malcolm-kee Thank you, do we will have more PRs before release?

@malcolm-kee malcolm-kee deleted the feat/overlay-open-editor branch October 13, 2022 00:53
@malcolm-kee
Copy link
Contributor Author

@alexander-akait I plan to have one more enhancement for reporting runtime error, but I foreseen that will probably take time as we probably want to allow configuration (e.g. react-error-overlay has logic specific to React).

@alexander-akait
Copy link
Member

Thanks for answer, no rush, I will wait, thank you

@malcolm-kee
Copy link
Contributor Author

@alexander-akait Right now I'm a bit stuck with how to differentiate between error thrown by webpack vs application code, do you have any suggestion?

Let me know if this should be discussed in another channel!

Meanwhile I'll continue try to understand how it was done in react-error-overlay.

@alexander-akait
Copy link
Member

@malcolm-kee Feel free to send a PR how you see to improve it and we will continue dicussion in the PR, thank you

@malcolm-kee malcolm-kee mentioned this pull request Oct 16, 2022
6 tasks
@nanianlisao
Copy link

@malcolm-kee This function does not seem to work, how should I verify this function

@malcolm-kee
Copy link
Contributor Author

@nanianlisao can you raise an issue with a reproduction? We have test for this so it's apparently working for us.

@nanianlisao
Copy link

@malcolm-kee Sorry about that, my bad. I thought we could do without the error-overlay-webpack-plugin plugin, but it looks like we're not there yet. We can only catch errors that are passed through the WebSocket for now.

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

Successfully merging this pull request may close these issues.

None yet

4 participants