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

fix: runtime process undefined error when resolved unexists file #741

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions crates/mako/src/runtime/runtime_hmr_entry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// swc will hoist
// working only with react-error-overlay@6.0.9
const ErrorOverlay = require('react-error-overlay');
const RefreshRuntime = require('react-refresh');
RefreshRuntime.injectIntoGlobalHook(self);
self.$RefreshReg$ = () => {};
Expand All @@ -9,17 +7,28 @@ self.$RefreshSig$ = () => (type) => type;
(function () {
let hadRuntimeError = false;

const enableErrorOverlay = true;
enableErrorOverlay &&
ErrorOverlay.startReportingRuntimeErrors({
onError: function () {
hadRuntimeError = true;
},
});
function startReportingRuntimeErrors(options) {
const errorHandler = () => {
options.onError();
hadRuntimeError = true;
};
window.addEventListener('error', errorHandler);
window.addEventListener('unhandledrejection', errorHandler);
return () => {
window.removeEventListener('error', errorHandler);
window.removeEventListener('unhandledrejection', errorHandler);
};
}

const stopReportingRuntimeError = startReportingRuntimeErrors({
onError: function () {
hadRuntimeError = true;
},
});

if (module.hot && typeof module.hot.dispose === 'function') {
module.hot.dispose(function () {
enableErrorOverlay && ErrorOverlay.stopReportingRuntimeErrors();
stopReportingRuntimeError();
});
}

Expand All @@ -31,7 +40,7 @@ self.$RefreshSig$ = () => (type) => type;
}

function getSocketUrl() {
let h = getHost();
const h = getHost();
const host = h.host;
const isHttps = h.protocol === 'https:';
return `${isHttps ? 'wss' : 'ws'}://${host}/__/hmr-ws`;
Expand Down

This file was deleted.

9 changes: 0 additions & 9 deletions crates/mako/src/snapshots/mako__update__tests__build-2.snap

This file was deleted.

7 changes: 0 additions & 7 deletions crates/mako/src/snapshots/mako__update__tests__build-3.snap

This file was deleted.

7 changes: 0 additions & 7 deletions crates/mako/src/snapshots/mako__update__tests__build.snap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions crates/mako/src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,3 @@ pub fn swc_preset_env_targets_from_map(map: HashMap<String, f32>) -> SwcPresetEn
let targets: SwcPresetEnvTargets = serde_json::from_str(&serialized_str).unwrap();
targets
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;

use super::swc_preset_env_targets_from_map;
use crate::assert_debug_snapshot;

#[test]
fn test_swc_preset_env_targets() {
let map = HashMap::from([("chrome".to_string(), 80.0)]);
let targets = swc_preset_env_targets_from_map(map);
assert_debug_snapshot!(&targets);
}
}