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(devtools): failed to resolve react-devtools-inline #5163

Merged
merged 3 commits into from
Dec 27, 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
6 changes: 6 additions & 0 deletions .changeset/pretty-radios-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/devtools-client': patch
---

fix(devtools): failed to resolve react-devtools-inline
fix(devtools): react-devtools-inline 包不存在导致报错
25 changes: 1 addition & 24 deletions packages/devtools/client/exports/mount.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
import { initialize } from 'react-devtools-inline/backend';
import routesManifest from '../dist/routes-manifest.json';

if (!window.opener) {
try {
// Delete existing devtools hooks registered by react devtools extension.
try {
delete window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
} catch {}
// Call this before importing React (or any other packages that might import React).
initialize(window);
// Deny react devtools extension to activate.
const originSubHook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__.sub;
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.sub = (e, handler) => {
if (e === 'devtools-backend-installed') {
return undefined;
}
return originSubHook(e, handler);
};
} catch (err) {
const e = new Error('Failed to inject React DevTools backend.');
e.cause = err;
console.error(e);
}
}

try {
const container = document.createElement('div');
container.className = '_modern_js_devtools_container';
Expand Down Expand Up @@ -60,4 +36,5 @@ try {
const e = new Error('Failed to execute mount point of DevTools.');
e.cause = err;
console.error(e);
console.error(err);
}
1 change: 1 addition & 0 deletions packages/devtools/client/src/entries/mount/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './react-devtools-backend';
import { createRoot } from 'react-dom/client';
import { parseQuery } from 'ufo';
import _ from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { initialize } from 'react-devtools-inline/backend';

if (!window.opener) {
try {
// Delete existing devtools hooks registered by react devtools extension.
try {
// @ts-expect-error
delete window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
} catch {}
// Call this before importing React (or any other packages that might import React).
initialize(window);
// Deny react devtools extension to activate.
const originSubHook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__.sub;
// @ts-expect-error
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.sub = (e: any, handler) => {
if (e === 'devtools-backend-installed') {
return undefined;
}
return originSubHook(e, handler);
};
} catch (err) {
const e = new Error('Failed to inject React DevTools backend.');
e.cause = err;
console.error(e);
}
}