diff --git a/components/ui-theme/src/UiTheme.tsx b/components/ui-theme/src/UiTheme.ts similarity index 68% rename from components/ui-theme/src/UiTheme.tsx rename to components/ui-theme/src/UiTheme.ts index 3340e401..1cbe6b88 100644 --- a/components/ui-theme/src/UiTheme.tsx +++ b/components/ui-theme/src/UiTheme.ts @@ -1,4 +1,4 @@ -import { FC, PropsWithChildren, createContext, useContext } from 'react'; +import { createElement, FC, PropsWithChildren, createContext, useContext } from 'react'; import { layers } from './layers.css'; import { vars } from './theme.css'; @@ -10,9 +10,9 @@ const uiTheme = { const Context = createContext(uiTheme); -export const UiTheme: FC = ({ children }) => ( - {children} -); +export const UiTheme: FC = ({ children }) => { + return createElement(Context.Provider, { value: uiTheme }, children); +}; if (import.meta.env.DEV) { UiTheme.displayName = 'ui-theme(UiTheme)'; diff --git a/package.json b/package.json index 90484a32..9463608b 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,9 @@ "eslint": "^10.0.0", "typescript": "^6.0.0" } + }, + "patchedDependencies": { + "@tabula/forge": "patches/@tabula__forge.patch" } }, "engines": { @@ -74,8 +77,8 @@ "@vanilla-extract/dynamic": "catalog:", "@vanilla-extract/vite-plugin": "^5.2.2", "change-case": "^5.4.4", - "eslint": "^10.2.1", "esbuild": "^0.28.0", + "eslint": "^10.2.1", "execa": "^9.6.1", "handlebars": "^4.7.9", "happy-dom": "catalog:", diff --git a/patches/@tabula__forge.patch b/patches/@tabula__forge.patch new file mode 100644 index 00000000..92d5f42a --- /dev/null +++ b/patches/@tabula__forge.patch @@ -0,0 +1,28 @@ +diff --git a/lib/index.js b/lib/index.js +index ebed270fae36eddde3d18d4960935659ce21d0de..200fe40c5c462ec34d20dea706109562bd165b83 100644 +--- a/lib/index.js ++++ b/lib/index.js +@@ -174,8 +174,21 @@ function renderDocs(docs) { + return docs.map((doc) => { + const { expression, ...storybook2 } = doc; + const instance = expression?.getName() ?? doc.displayName; +- return `${instance}.__docgenInfo = ${JSON.stringify(storybook2, null, 2)};`; +- }).join("\n"); ++ const cache = new Set(); ++ const safeStringify = JSON.stringify(storybook2, (key, value) => { ++ if (typeof value === "object" && value !== null) { ++ if (cache.has(value)) { ++ return "[Circular]"; ++ } ++ if (value.constructor && (value.constructor.name === "SourceFileObject" || value.constructor.name === "NodeObject")) { ++ return "[TSNode]"; ++ } ++ cache.add(value); ++ } ++ return value; ++ }, 2); ++ return `${instance}.__docgenInfo = ${safeStringify};`; ++ }).join("\\n"); + } + + // src/plugins/reactDocgenPlugin/reactDocgenPlugin.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f28abdb..c0a7186f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -64,6 +64,11 @@ catalogs: specifier: ^4.1.5 version: 4.1.5 +patchedDependencies: + '@tabula/forge': + hash: d777bad36076a034e5af764d7ed950497556d0a761e7cdd17721b41528055f2b + path: patches/@tabula__forge.patch + importers: .: @@ -106,7 +111,7 @@ importers: version: 1.1.1(@typescript-eslint/eslint-plugin@8.59.0(@typescript-eslint/parser@8.59.0(eslint@10.2.1(jiti@2.6.1))(typescript@6.0.3))(eslint@10.2.1(jiti@2.6.1))(typescript@6.0.3))(@typescript-eslint/utils@8.59.0(eslint@10.2.1(jiti@2.6.1))(typescript@6.0.3))(eslint-import-resolver-node@0.3.9)(eslint@10.2.1(jiti@2.6.1))(typescript@6.0.3)(vitest@4.1.5(@types/node@24.12.2)(happy-dom@20.9.0)(vite@8.0.10(@types/node@24.12.2)(esbuild@0.28.0)(jiti@2.6.1)(sass-embedded@1.99.0)(sass@1.99.0)(tsx@4.21.0))) '@tabula/forge': specifier: ^4.0.2 - version: 4.0.2(jiti@2.6.1)(tsx@4.21.0)(typescript@6.0.3) + version: 4.0.2(patch_hash=d777bad36076a034e5af764d7ed950497556d0a761e7cdd17721b41528055f2b)(jiti@2.6.1)(tsx@4.21.0)(typescript@6.0.3) '@tabula/prettier-config': specifier: workspace:* version: link:configs/prettier-config @@ -7150,7 +7155,7 @@ snapshots: - supports-color - vitest - '@tabula/forge@4.0.2(jiti@2.6.1)(tsx@4.21.0)(typescript@6.0.3)': + '@tabula/forge@4.0.2(patch_hash=d777bad36076a034e5af764d7ed950497556d0a761e7cdd17721b41528055f2b)(jiti@2.6.1)(tsx@4.21.0)(typescript@6.0.3)': dependencies: '@babel/core': 7.29.0 '@babel/types': 7.29.0 diff --git a/test-json.js b/test-json.js new file mode 100644 index 00000000..cc1fb8bf --- /dev/null +++ b/test-json.js @@ -0,0 +1,12 @@ +const stringify = (obj) => { + const cache = new Set(); + return JSON.stringify(obj, (key, value) => { + if (typeof value === 'object' && value !== null) { + if (cache.has(value)) { + return '[Circular]'; + } + cache.add(value); + } + return value; + }, 2); +};