-
Notifications
You must be signed in to change notification settings - Fork 24
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(devtool): add react devtool support [WIP] #68
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export function initDevTools() { | ||
// rdtHook -> React Devtools hook | ||
const rdtHook = (window).__REACT_DEVTOOLS_GLOBAL_HOOK__; | ||
|
||
// the developer has not installed react devtools | ||
if(rdtHook == null) return; | ||
|
||
catchErrors(() => { | ||
let isDev = false; | ||
|
||
try { | ||
isDev = process.env.NODE_ENV !== 'production'; | ||
} | ||
catch {} | ||
|
||
window.parent.postMessage({ | ||
source: 'react-devtools-detector', | ||
reactBuildType: isDev | ||
? 'development' | ||
: 'production' | ||
}, | ||
'*'); | ||
})(); | ||
} | ||
|
||
function catchErrors(fn) { | ||
return function(...args) { | ||
try { | ||
fn(args); | ||
} | ||
catch(e) { | ||
console.error(`React Devtools encountered an error`); | ||
console.error(e); | ||
} | ||
}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add empty line at EOF. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure probably we need to add prettier, husky |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { initDevTools } from './devtool'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will also need to add this file on the dev build right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I think it should be opt-int by the user if the user adds import '../src/debug'; they will get support for React dev tool. do you think that there is any other better way of doing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On rollup we can add this on dev bundle. and exclude it otherwise. |
||
|
||
initDevTools(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add empty line at EOF. |
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.
when a person runs app in Development env, should we add a log recommending them to use React DevTools?
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.
Yes we should add that