Skip to content

🎥 Make videos programmatically with React

show stacktrace in timeline

Jonny Burgerb98b3ac2c469
diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.ts
index 1d4882914f..faab2f43bd 100644
--- a/packages/bundler/src/webpack-config.ts
+++ b/packages/bundler/src/webpack-config.ts
@@ -91,7 +91,7 @@ export const webpackConfig = ({
ignored: ['**/.git/**', '**/node_modules/**'],
},
- devtool: 'cheap-module-source-map',
+ devtool: 'inline-source-map',
entry: [
// Fast Refresh must come first,
// because setup-environment imports ReactDOM.
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index 36772e0221..b4f6432b1d 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -7,6 +7,7 @@ import {
TIMELINE_LAYER_HEIGHT,
} from '../../helpers/timeline-layout';
import {TimelineLayerEye} from './TimelineLayerEye';
+import {TimelineStack} from './TimelineStack';
const SPACING = 5;
@@ -87,6 +88,7 @@ export const TimelineListItem: React.FC<{
<div title={text || '<Sequence>'} style={textStyle}>
{text || '<Sequence>'}
</div>
+ {sequence.stack ? <TimelineStack stack={sequence.stack} /> : null}
</div>
);
};
diff --git a/packages/studio/src/components/Timeline/TimelineStack.tsx b/packages/studio/src/components/Timeline/TimelineStack.tsx
new file mode 100644
index 0000000000..b506d1fb31
--- /dev/null
+++ b/packages/studio/src/components/Timeline/TimelineStack.tsx
@@ -0,0 +1,79 @@
+import {useCallback, useEffect, useState} from 'react';
+import type {SourceMapConsumer} from 'source-map';
+import type {OriginalPosition} from '../../error-overlay/react-overlay/utils/get-source-map';
+import {
+ getOriginalPosition,
+ getSourceMap,
+} from '../../error-overlay/react-overlay/utils/get-source-map';
+import {getFileContents} from '../../error-overlay/react-overlay/utils/unmapper';
+import {VERY_LIGHT_TEXT} from '../../helpers/colors';
+import {getLocationOfSequence} from '../../helpers/get-location-of-sequence';
+import {openInEditor} from '../../helpers/open-in-editor';
+
+export const TimelineStack: React.FC<{
+ stack: string;
+}> = ({stack}) => {
+ const [originalLocation, setOriginalLocation] =
+ useState<OriginalPosition | null>(null);
+
+ const onClick = useCallback(() => {
+ if (!originalLocation) {
+ return;
+ }
+
+ openInEditor({
+ originalColumnNumber: originalLocation.column,
+ originalFileName: originalLocation.source,
+ originalFunctionName: null,
+ originalLineNumber: originalLocation.line,
+ originalScriptCode: null,
+ }).catch(() => {
+ // TODO: Show error notification
+ });
+ }, [originalLocation]);
+
+ useEffect(() => {
+ const location = getLocationOfSequence(stack);
+
+ if (location) {
+ getFileContents(location?.fileName as string)
+ .then((fileContents) => {
+ return getSourceMap(
+ location.fileName as string,
+ fileContents as string,
+ );
+ })
+ .then((frame) => {
+ return getOriginalPosition(
+ frame as SourceMapConsumer,
+ location.lineNumber as number,
+ location.columnNumber as number,
+ );
+ })
+ .then((frame) => {
+ setOriginalLocation(frame);
+ })
+ .catch((err) => {
+ console.log(err);
+ });
+ }
+ }, [stack]);
+
+ if (!originalLocation) {
+ return null;
+ }
+
+ return (
+ <div
+ onClick={onClick}
+ style={{
+ fontSize: 12,
+ color: VERY_LIGHT_TEXT,
+ marginLeft: 10,
+ cursor: 'pointer',
+ }}
+ >
+ {originalLocation.source}:{originalLocation.line}
+ </div>
+ );
+};
diff --git a/packages/studio/src/error-overlay/react-overlay/utils/get-source-map.ts b/packages/studio/src/error-overlay/react-overlay/utils/get-source-map.ts
index e0ef8d0c72..c137e8591d 100644
--- a/packages/studio/src/error-overlay/react-overlay/utils/get-source-map.ts
+++ b/packages/studio/src/error-overlay/react-overlay/utils/get-source-map.ts
@@ -14,11 +14,17 @@
import type {RawSourceMap} from 'source-map';
import {SourceMapConsumer} from 'source-map';
+export type OriginalPosition = {
+ line: number | null;
+ column: number | null;
+ source: string | null;
+};
+
export const getOriginalPosition = (
source_map: SourceMapConsumer,
line: number,
column: number,
-): {source: string | null; line: number | null; column: number | null} => {
+): OriginalPosition => {
const result = source_map.originalPositionFor({
line,
column,
diff --git a/packages/studio/src/error-overlay/react-overlay/utils/unmapper.ts b/packages/studio/src/error-overlay/react-overlay/utils/unmapper.ts
index d7fb5494d0..410d195fe5 100644
--- a/packages/studio/src/error-overlay/react-overlay/utils/unmapper.ts
+++ b/packages/studio/src/error-overlay/react-overlay/utils/unmapper.ts
@@ -21,7 +21,7 @@ import type {
SymbolicatedStackFrame,
} from './stack-frame';
-const getFileContents = async (fileName: string) => {
+export const getFileContents = async (fileName: string) => {
const res = await fetch(fileName as string);
const fileContents = await res.text();
diff --git a/packages/studio/src/helpers/calculate-timeline.ts b/packages/studio/src/helpers/calculate-timeline.ts
index cba2961141..9041a43238 100644
--- a/packages/studio/src/helpers/calculate-timeline.ts
+++ b/packages/studio/src/helpers/calculate-timeline.ts
@@ -1,5 +1,4 @@
import type {TSequence} from 'remotion';
-import {getLocationOfSequence} from './get-location-of-sequence';
import {
getCascadedStart,
getTimelineVisibleDuration,
@@ -95,9 +94,6 @@ export const calculateTimeline = ({
const uniqueTracks: TrackWithHash[] = [];
for (const track of tracks) {
- const location = getLocationOfSequence(track.sequence.stack);
- console.log(location);
-
if (
!uniqueTracks.find((t) => t.hash === track.hash) &&
track.sequence.showInTimeline &&