🎥 Make videos programmatically with React
stack
Jonny Burger58ef8ec78f5c
diff --git a/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts b/packages/studio/src/components/Timeline/TimelineStack/get-stack.tsindex 89c19759ee..8c9be0bf72 100644--- a/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts+++ b/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts@@ -2,22 +2,64 @@ import {SourceMapConsumer} from 'source-map';import {getOriginalPosition} from '../../../error-overlay/react-overlay/utils/get-source-map';import {getLocationOfSequence} from '../../../helpers/get-location-of-sequence';-export const getOriginalLocationFromStack = async (stack: string) => {- const location = getLocationOfSequence(stack);- if (!location) {- return null;+type Waiter = {+ id: string;+ forFileName: string;+ resolve: (consumer: SourceMapConsumer) => void;+};++const waiters: Waiter[] = [];++const sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};+const isCreating: Record<string, boolean> = {};++const getSourceMapCache = async (fileName: string) => {+ if (sourceMapConsumerCache[fileName]) {+ return sourceMapConsumerCache[fileName];+ }++ if (isCreating[fileName]) {+ return new Promise<SourceMapConsumer>((resolve) => {+ waiters.push({+ id: String(Math.random()),+ forFileName: fileName,+ resolve,+ });+ });}- const res = await fetch(`${location.fileName}.map`);+ isCreating[fileName] = true;+ const res = await fetch(`${fileName}.map`);const json = await res.json();- const map = await new Promise((resolve) => {+ const map = await new Promise<SourceMapConsumer>((resolve) => {SourceMapConsumer.with(json, null, (consumer) => {resolve(consumer);});});+ waiters.filter((w) => {+ if (w.forFileName === fileName) {+ w.resolve(map);+ return false;+ }++ return true;+ });+ sourceMapConsumerCache[fileName] = map;+ isCreating[fileName] = false;+ return map;+};++export const getOriginalLocationFromStack = async (stack: string) => {+ const location = getLocationOfSequence(stack);++ if (!location) {+ return null;+ }++ const map = await getSourceMapCache(location.fileName);const originalPosition = getOriginalPosition(- map as SourceMapConsumer,+ map,location.lineNumber as number,location.columnNumber as number,);diff --git a/packages/studio/src/components/Timeline/TimelineStack/index.tsx b/packages/studio/src/components/Timeline/TimelineStack/index.tsxindex 20d6f94644..95e0c90288 100644--- a/packages/studio/src/components/Timeline/TimelineStack/index.tsx+++ b/packages/studio/src/components/Timeline/TimelineStack/index.tsx@@ -1,9 +1,8 @@-import {useCallback, useEffect, useState} from 'react';+import React, {useCallback, useEffect, useMemo, useState} from 'react';import {SourceMapConsumer} from 'source-map';import type {OriginalPosition} from '../../../error-overlay/react-overlay/utils/get-source-map';import {SOURCE_MAP_ENDPOINT} from '../../../error-overlay/react-overlay/utils/source-map-endpoint';import {LIGHT_TEXT, VERY_LIGHT_TEXT} from '../../../helpers/colors';-import {getLocationOfSequence} from '../../../helpers/get-location-of-sequence';import {openInEditor} from '../../../helpers/open-in-editor';import {Spacing} from '../../layout';import {sendErrorNotification} from '../../Notifications/NotificationCenter';@@ -46,20 +45,14 @@ export const TimelineStack: React.FC<{}, [originalLocation]);useEffect(() => {- const location = getLocationOfSequence(stack);-- if (location) {- getOriginalLocationFromStack(stack)- .then((frame) => {- setOriginalLocation(frame);- })- .catch((err) => {- // eslint-disable-next-line no-console- console.error('Could not get original location of Sequence', err);- });- } else {- setOriginalLocation(null);- }+ getOriginalLocationFromStack(stack)+ .then((frame) => {+ setOriginalLocation(frame);+ })+ .catch((err) => {+ // eslint-disable-next-line no-console+ console.error('Could not get original location of Sequence', err);+ });}, [stack]);const onPointerEnter = useCallback(() => {@@ -70,6 +63,22 @@ export const TimelineStack: React.FC<{setHovered(false);}, []);+ const style = useMemo((): React.CSSProperties => {+ return {+ fontSize: 12,+ color: opening ? VERY_LIGHT_TEXT : hovered ? LIGHT_TEXT : VERY_LIGHT_TEXT,+ marginLeft: 10,+ cursor: 'pointer',+ display: 'flex',+ flexDirection: 'row',+ alignItems: 'center',+ whiteSpace: 'nowrap',+ textOverflow: 'ellipsis',+ overflow: 'hidden',+ flexShrink: 100000,+ };+ }, [hovered, opening]);+if (!originalLocation) {return null;}@@ -79,19 +88,7 @@ export const TimelineStack: React.FC<{onPointerEnter={onPointerEnter}onPointerLeave={onPointerLeave}onClick={onClick}- style={{- fontSize: 12,- color: opening- ? VERY_LIGHT_TEXT- : hovered- ? LIGHT_TEXT- : VERY_LIGHT_TEXT,- marginLeft: 10,- cursor: 'pointer',- display: 'flex',- flexDirection: 'row',- alignItems: 'center',- }}+ style={style}>{originalLocation.source}:{originalLocation.line}{opening ? (