Site: deduplicate the CodeSandbox JS/TS sandbox define-API payload in index.jsx
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 75/100
- issue の種類
- リファクタリング
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, react, typescript
調査の方向性
packages/tdesign-react/site/src/components/codesandbox/index.jsxと、packages/tdesign-react/site/test/codesandbox.test.mjsにあるリグレッション仕様を読みます。JSとTSのファイルセットを維持し、条件付きのtsconfig.jsonも含めて、共有されるCodeSandboxペイロードとリクエストパスを抽出します。Nodeのテスト仕様を実行し、Sandboxの作成に成功したときに返されたURLが引き続き開かれることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Problem
packages/tdesign-react/site/src/components/codesandbox/index.jsx issues the CodeSandbox define request through two fully duplicated fetch blocks — one for TypeScript demos and one for JS demos — that differ only in file extensions (src/main.tsx vs src/main.jsx, src/demo.tsx vs src/demo.jsx, and the extra tsconfig.json for TS). Any future fix to the shared payload (manifest, index.html, styles, entry file) must be edited in two places and can silently drift apart.
Note: this issue is scoped to the index.jsx payload deduplication only; the separate ReactDOM.render -> createRoot template change in content.js is tracked elsewhere and is intentionally out of scope here.
Proposal
Extract a single shared code path that builds the file map (parameterized by the demo language for extensions and the conditional tsconfig.json) and posts it to https://codesandbox.io/api/v1/sandboxes/define?json=1, keeping identical filenames, identical shared files, and identical success behavior (opening https://codesandbox.io/s/<id>?file=/src/demo.<ext>).
Scope
Site only: packages/tdesign-react/site/src/components/codesandbox/index.jsx. No component API, type.ts, defaultProps.ts, or submodule changes.
Validation
Regression tests are pending — a node:test spec at packages/tdesign-react/site/test/codesandbox.test.mjs asserts a single define-API request path while preserving both JS and TS file sets; it currently fails on the duplicated baseline. Manual check: pnpm dev, open a component page, generate a JS and a TS demo sandbox and confirm identical payloads other than the language-specific files.
Executed reproduction
Baseline: 0701c679bd4608c5445ee7ce61d94b916c70e4da
{
"argv": [
"node",
"--test",
"packages/tdesign-react/site/test/codesandbox.test.mjs"
],
"exit_code": 1,
"output": "✖ CodeSandbox define API request is built once and shared for JS and TS demos (3.4059ms)\n✔ sandbox generation still supports both JS and TS demos (0.3662ms)\n✔ successful sandbox creation still opens the returned sandbox URL (0.1314ms)\nℹ tests 3\nℹ suites 0\nℹ pass 2\nℹ fail 1\nℹ cancelled 0\nℹ skipped 0\nℹ todo 0\nℹ duration_ms 128.971\n\n✖ failing tests:\n\ntest at packages\\tdesign-react\\site\\test\\codesandbox.test.mjs:15:1\n✖ CodeSandbox define API request is built once and shared for JS and TS demos (3.4059ms)\n AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:\n \n 2 !== 1\n \n at TestContext.<anonymous> (file:///C:/Users/silver/Documents/github/oss-contributor/workspaces/Tencent--tdesign-react--hunt-2cafd23230c6/packages/tdesign-react/site/test/codesandbox.test.mjs:17:10)\n at Test.runInAsyncScope (node:async_hooks:226:14)\n at Test.run (node:internal/test_runner/test:1397:25)\n at Test.start (node:internal/test_runner/test:1257:17)\n at startSubtestAfterBootstrap (node:internal/test_runner/harness:387:17) {\n generatedMessage: true,\n code: 'ERR_ASSERTION',\n actual: 2,\n expected: 1,\n operator: 'strictEqual',\n diff: 'simple'\n }\n\n"
}
Regression test
New regression file: packages/tdesign-react/site/test/codesandbox.test.mjs
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import test from 'node:test';
const codesandboxDir = join(dirname(fileURLToPath(import.meta.url)), '../src/components/codesandbox');
const indexSource = readFileSync(join(codesandboxDir, 'index.jsx'), 'utf8');
// Regression: the CodeSandbox "define" request must be issued through a single
// shared code path. The baseline builds the whole fetch payload twice (once for
// `.tsx` demos, once for `.jsx` demos), so any template fix has to be edited in
// two places and can drift apart. On the unfixed source this assertion fails
// with `2 !== 1`.
test('CodeSandbox define API request is built once and shared for JS and TS demos', () => {
const occurrences = indexSource.match(/codesandbox\.io\/api\/v1\/sandboxes\/define/g) ?? [];
assert.equal(occurrences.length, 1);
});
// Boundaries of the refactor: deduplicating the payload must not drop support
// for either demo language or change what the action does on success.
test('sandbox generation still supports both JS and TS demos', () => {
// Language detection still drives which file names are posted.
assert.match(indexSource, /currentLangIndex|isTypeScriptDemo/);
assert.match(indexSource, /tsx/);
assert.match(indexSource, /jsx/);
// TS demos keep their tsconfig; JS demos still omit it.
assert.match(indexSource, /tsconfig\.json/);
// Every variant still ships the shared manifest, page and styles.
assert.match(indexSource, /'package\.json'/);
assert.match(indexSource, /'public\/index\.html'/);
assert.match(indexSource, /'src\/index\.css'/);
});
test('successful sandbox creation still opens the returned sandbox URL', () => {
assert.match(indexSource, /window\.open\(`https:\/\/codesandbox\.io\/s\//);
});
AI-assisted contribution.
- 主要言語
- TypeScript
- スター
- 973
- フォーク
- 379
- 平均マージ
- 4日 7時間
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Tencent/tdesign-react のほかの issue
-
[Table] reserveSelectedRowOnPaginate=false 时表头全选包含其他页数据対応中かも @dvd233 が 32 日前に担当しました。 オープン🐞 bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Tencent/tdesign-react#4416 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
[Dialog] 支持焦点落点可配置、Enter 键确认与焦点循环(含 DialogPlugin 对齐)対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン🐞 bug 💪🏻 enhancement in progress
難易度 5/5 1週間以上 初心者へのやさしさ 18/100
Tencent/tdesign-react#4430 · コメント 3 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Chatbot] 似乎不支持ag-ui中的interrupts再び着手できるかも @LzhengH が 52 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン💪🏻 enhancement
Tencent/tdesign-react#4400 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
💪🏻 enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
Tencent/tdesign-react#4253 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
💪🏻 enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
Tencent/tdesign-react#4246 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
Tencent/tdesign-react の issue をすべて見る
似ている issue
-
Add: Shop On TV SDオープンcheck:passed streams:add
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
bug implicit-state
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
book-layout.spec fails when the similar-books rail holds other projects' books対応中かも @praetorianer777 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
praetorianer777/GoTome#373 ·
メンテナーはふだん 1 日以内に返信
-
area:cards enhancement ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
fil-donadoni/tolaria#8883 ·
メンテナーはふだん 1 日以内に返信
-
xsd:integer cast from a string rejects negative numbers, a leading + and surrounding whitespaceオープンbug 🐛
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
comunica/comunica#1960 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信