Skip to content

Commit

Permalink
fix: add logging mutex, better handling of undefined props in render
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Mar 20, 2024
1 parent bec62ef commit 20686d7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
31 changes: 27 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -16,8 +16,10 @@
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^9.0.1",
"@semantic-release/release-notes-generator": "^10.0.3",
"@tscircuit/builder": "file:.yalc/@tscircuit/builder",
"@tscircuit/builder": "^1.5.8",
"@types/lodash": "^4.17.0",
"@types/react-reconciler": "^0.28.0",
"async-mutex": "^0.5.0",
"ava": "^4.3.3",
"axios": "^1.3.2",
"esbuild": "^0.15.18",
Expand Down
12 changes: 8 additions & 4 deletions src/lib/render.ts
Expand Up @@ -17,6 +17,7 @@ import {
BuilderType,
} from "./get-builder-for-type"
import { getSchematicPropertiesFromProps } from "./get-schematic-properties-from-props"
import _ from "lodash"

export type RootContainer = {}

Expand Down Expand Up @@ -71,10 +72,13 @@ export const hostConfig: HostConfig<
}

if ("setProps" in instance) {
const propsWithElms = {
...props,
footprint,
}
const propsWithElms = _.omitBy(
{
...props,
footprint,
},
_.isUndefined
)
;(instance as any).setProps(propsWithElms)
return instance
}
Expand Down
33 changes: 21 additions & 12 deletions tests/utils/log-layout.ts
@@ -1,4 +1,5 @@
import defaultAxios from "axios"
import { Mutex } from "async-mutex"

const DEBUG_SRV = `https://debug.tscircuit.com`

Expand All @@ -22,6 +23,8 @@ function findSource(elm: any, sources: Array<any>) {
return null
}

const request_mutex = new Mutex()

let layout_server_healthy: boolean | null = null
export const logLayout = async (
layout_group_name: string,
Expand All @@ -43,18 +46,24 @@ export const logLayout = async (
}

for (const layout_name of ["schematic", "pcb"]) {
await axios.post("/api/soup_group/add_soup", {
soup_group_name: `react-fiber:${layout_group_name}`,
soup_name: layout_name,
username: "tmp",
content: {
elements: objects
.filter((o) => o.type?.includes(layout_name))
.map((o: any) => ({
...o,
source: findSource(o, objects),
})),
},
await request_mutex.runExclusive(async () => {
await axios
.post("/api/soup_group/add_soup", {
soup_group_name: `react-fiber:${layout_group_name}`,
soup_name: layout_name,
username: "tmp",
content: {
elements: objects
.filter((o) => o.type?.includes(layout_name))
.map((o: any) => ({
...o,
source: findSource(o, objects),
})),
},
})
.catch((e) => {
console.warn(`Couldn't log layout: ${layout_group_name}`)
})
})
}
}

0 comments on commit 20686d7

Please sign in to comment.