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 overlay for build errors when using hmr #1074
Add overlay for build errors when using hmr #1074
Conversation
0543a8b
to
8b22f23
Compare
Siiiiick! Nice work 🎉 |
Any idea why these tests are failing? We've been trying to run the tests locally and different tests are failing. The one that's consistent is the |
@lmontopo In the test environment some tests just fail from time to time. To fix the Uncaught typeError however I think you have to change this part: Lines 309 to 315 in 3ddaec9
Into something like this: run(bundle, {
console: {
error(msg) {
logs.push(msg);
}
},
document: {
getElementById(id) {
// return a mock element object
},
createElement(element) {
// return a mock element object
}
}
}); This is because the hmr tests are ran in node.js instead of a browser and we mock browsers global variables. |
Thanks @DeMoorJasper, that makes sense (mocking those methods). We'll look into doing this soon (probably tomorrow) and then we'll push updates! :) |
src/builtins/hmr-runtime.js
Outdated
message.style.fontWeight = 'bold'; | ||
message.style.marginTop = '20px'; | ||
|
||
return overlay; |
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.
what do you think about just using innerHTML
for most of this? Might be easier to read?
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.
just pushed up a new commit to try it this way! Took some time to figure out how to make it safe (i.e. how to ensure the message and stack trace are html encoded) but we figured it out. Let me know what you think.
src/builtins/hmr-runtime.js
Outdated
removeErrorOverlay(); | ||
|
||
var overlay = createErrorOverlay(data); | ||
document.body.append(overlay); |
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.
We should use appendChild
instead of append
.
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.
👍
src/builtins/hmr-runtime.js
Outdated
'</div>' | ||
) | ||
|
||
overlay.innerHTML = html; |
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.
Instead of wrapping the overlay in another div, we could try returningoverlay.firstChild
instead:
function createErrorOverlay(data) {
var overlay = document.createElement('div');
overlay.innerHTML = (
'<div id="' + OVERLAY_ID + ' ...' +
'</div>'
);
return overlay.firstChild;
}
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.
We decided to get rid of the html var as you suggested, but we kept the outer div because it just seemed more straightforward / easy to read and understand.
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.
👍
Instead of using the DOM api, create a string with the desired overlay html and assign it to an element using innerHTML. Related to Issue parcel-bundler#413
b038130
to
f46e21e
Compare
Related to Issue parcel-bundler#413
Codecov Report
@@ Coverage Diff @@
## master #1074 +/- ##
==========================================
+ Coverage 88.38% 92.75% +4.36%
==========================================
Files 71 72 +1
Lines 3643 2815 -828
==========================================
- Hits 3220 2611 -609
+ Misses 423 204 -219
Continue to review full report at Codecov.
|
yay! thanks for adding the tests @devongovett. Super psyched this was merged! |
Yep, thanks for merging! I'm glad to have contributed to an awesome tool :) |
Thanks for contributing it! I'm excited to use it. :) |
Fixes #413
Worked as a team with @sibartlett and @narsaynorath