Skip to content

Commit

Permalink
footprinter fixes (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar authored Oct 15, 2024
1 parent f6ec6fc commit 97326ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@types/ms": "^0.7.34",
"@typescript/ata": "^0.9.7",
"@valtown/codemirror-ts": "^2.2.0",
"circuit-json": "^0.0.85",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "1.0.0",
Expand All @@ -76,6 +77,7 @@
"immer": "^10.1.1",
"input-otp": "^1.2.4",
"jose": "^5.9.3",
"jscad-electronics": "^0.0.11",
"lucide-react": "^0.445.0",
"ms": "^2.1.3",
"next-themes": "^0.3.0",
Expand All @@ -97,7 +99,7 @@
"@babel/standalone": "^7.25.6",
"@biomejs/biome": "^1.9.2",
"@playwright/test": "^1.48.0",
"@tscircuit/core": "^0.0.113",
"@tscircuit/core": "^0.0.114",
"@tscircuit/prompt-benchmarks": "^0.0.14",
"@types/babel__standalone": "^7.1.7",
"@types/bun": "^1.1.10",
Expand All @@ -107,7 +109,7 @@
"@typescript/vfs": "^1.6.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20",
"circuit-to-svg": "^0.0.37",
"circuit-to-svg": "^0.0.40",
"globals": "^15.9.0",
"postcss": "^8.4.47",
"prismjs": "^1.29.0",
Expand Down
14 changes: 9 additions & 5 deletions src/hooks/use-run-tsx/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useReducer, useState } from "react"
import { useEffect, useMemo, useReducer, useRef, useState } from "react"
import * as React from "react"
import { safeCompileTsx, useCompiledTsx } from "../use-compiled-tsx"
import * as tscircuitCore from "@tscircuit/core"
Expand Down Expand Up @@ -42,6 +42,7 @@ export const useRunTsx = ({
isLoading: false,
})
const apiBaseUrl = useSnippetsBaseApiUrl()
const preSuppliedImportsRef = useRef<Record<string, any>>({})

useEffect(() => {
if (tsxRunTriggerCount === 0) return
Expand All @@ -66,13 +67,16 @@ export const useRunTsx = ({
})
}

const imports = getImportsFromCode(code!).filter((imp) =>
const userCodeTsciImports = getImportsFromCode(code!).filter((imp) =>
imp.startsWith("@tsci/"),
)

const preSuppliedImports: Record<string, any> = {}
const preSuppliedImports: Record<string, any> =
preSuppliedImportsRef.current

async function addImport(importName: string, depth: number = 0) {
if (!importName.startsWith("@tsci/")) return
if (preSuppliedImports[importName]) return
if (depth > 5) {
console.log("Max depth for imports reached")
return
Expand Down Expand Up @@ -111,8 +115,8 @@ export const useRunTsx = ({
}
}

for (const importName of imports) {
await addImport(importName)
for (const userCodeTsciImport of userCodeTsciImports) {
await addImport(userCodeTsciImport)
}

preSuppliedImports["@tscircuit/core"] = tscircuitCore
Expand Down

0 comments on commit 97326ee

Please sign in to comment.