2018-12-11 23:26:24 +03:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
import {getStackFrames} from './react-error-overlay/utils/getStackFrames';
|
|
|
|
import StackTrace from './react-error-overlay/containers/StackTrace';
|
2018-12-11 23:26:24 +03:00
|
|
|
|
|
|
|
export default class StackTraceTab extends Component {
|
2018-12-12 19:34:22 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
stackFrames: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
componentDidMount() {
|
2018-12-12 23:45:37 +03:00
|
|
|
// console.log("StackTraceTab mounted");
|
2018-12-12 19:34:22 +03:00
|
|
|
this.checkForStackTrace();
|
|
|
|
}
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const {action, actions} = prevProps;
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
if(action !== this.props.action || actions !== this.props.actions) {
|
|
|
|
this.checkForStackTrace();
|
2018-12-11 23:26:24 +03:00
|
|
|
}
|
2018-12-12 19:34:22 +03:00
|
|
|
}
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
checkForStackTrace() {
|
|
|
|
const {action, actions: liftedActionsById} = this.props;
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
if(!action) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
const liftedActions = Object.values(liftedActionsById);
|
|
|
|
const liftedAction = liftedActions.find(liftedAction => liftedAction.action === action);
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
if(liftedAction && typeof liftedAction.stack === 'string') {
|
|
|
|
const deserializedError = Object.assign(new Error(), {stack: liftedAction.stack});
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
getStackFrames(deserializedError)
|
2018-12-12 23:45:37 +03:00
|
|
|
.then(stackFrames => {
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
if (process.env.NODE_ENV === 'development') console.log('Stack frames: ', stackFrames);
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
this.setState({stackFrames, currentError: deserializedError});
|
|
|
|
});
|
2018-12-11 23:26:24 +03:00
|
|
|
}
|
2018-12-12 19:34:22 +03:00
|
|
|
else {
|
|
|
|
this.setState({stackFrames: []});
|
|
|
|
}
|
|
|
|
}
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
onStackLocationClicked = (fileLocation = {}) => {
|
2018-12-12 23:45:37 +03:00
|
|
|
// console.log("Stack location args: ", ...args);
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
const {fileName, lineNumber} = fileLocation;
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
if(fileName && lineNumber) {
|
|
|
|
const matchingStackFrame = this.state.stackFrames.find(stackFrame => {
|
|
|
|
const matches = (
|
2018-12-12 23:45:37 +03:00
|
|
|
(stackFrame._originalFileName === fileName && stackFrame._originalLineNumber === lineNumber) ||
|
|
|
|
(stackFrame.fileName === fileName && stackFrame.lineNumber === lineNumber)
|
|
|
|
);
|
2018-12-12 19:34:22 +03:00
|
|
|
return matches;
|
|
|
|
});
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 23:45:37 +03:00
|
|
|
// console.log("Matching stack frame: ", matchingStackFrame);
|
2018-12-11 23:26:24 +03:00
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
if(matchingStackFrame) {
|
2018-12-12 23:45:37 +03:00
|
|
|
/*
|
|
|
|
const frameIndex = this.state.stackFrames.indexOf(matchingStackFrame);
|
|
|
|
const originalStackFrame = parsedFramesNoSourcemaps[frameIndex];
|
|
|
|
console.log("Original stack frame: ", originalStackFrame);
|
|
|
|
*/
|
2018-12-12 19:34:22 +03:00
|
|
|
const adjustedLineNumber = Math.max(lineNumber - 1, 0);
|
2018-12-11 23:26:24 +03:00
|
|
|
|
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
chrome.devtools.panels.openResource(fileName, adjustedLineNumber, (result) => {
|
2018-12-12 23:45:37 +03:00
|
|
|
//console.log("openResource callback args: ", callbackArgs);
|
|
|
|
//console.log("Testing");
|
2018-12-12 19:34:22 +03:00
|
|
|
if(result.isError) {
|
|
|
|
const {fileName: finalFileName, lineNumber: finalLineNumber} = matchingStackFrame;
|
|
|
|
const adjustedLineNumber = Math.max(finalLineNumber - 1, 0);
|
|
|
|
chrome.devtools.panels.openResource(finalFileName, adjustedLineNumber, (result) => {
|
2018-12-12 23:45:37 +03:00
|
|
|
// console.log("openResource result: ", result);
|
2018-12-12 19:34:22 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-12-11 23:26:24 +03:00
|
|
|
}
|
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
}
|
2018-12-11 23:26:24 +03:00
|
|
|
|
|
|
|
|
2018-12-12 19:34:22 +03:00
|
|
|
render() {
|
|
|
|
const {stackFrames} = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={{backgroundColor: 'white', color: 'black'}}>
|
2018-12-11 23:26:24 +03:00
|
|
|
<h2>Dispatched Action Stack Trace</h2>
|
2018-12-12 19:34:22 +03:00
|
|
|
<div style={{display: 'flex', flexDirection: 'column'}}>
|
2018-12-11 23:26:24 +03:00
|
|
|
<StackTrace
|
|
|
|
stackFrames={stackFrames}
|
|
|
|
errorName={"N/A"}
|
|
|
|
contextSize={3}
|
|
|
|
editorHandler={this.onStackLocationClicked}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-12-12 19:34:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|