-
Notifications
You must be signed in to change notification settings - Fork 0
Wrap ALL JSX expressions with computed() for universal reactivity #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: takuma-ru <[email protected]>
Co-authored-by: takuma-ru <[email protected]>
|
@copilot 例 const count = signal(0)
const s = "static text"
return (
<div data-count={count.value}>{count.value}</div>
<div data-static{s}>{s}</div>
)を変換すると const count = signal(0)
const s = "static text"
return (
<div data-count={computed(()=>count.value)}>{computed(()=>count.value)}</div>
<div data-static{computed(()=>s)}>{computed(()=>s)}</div>
)となるようなトラバーサーに変更して |
Co-authored-by: takuma-ru <[email protected]>
|
@copilot jsx構文内部で{}が使用されている箇所を全て、{computed(() => 原文)}に変換するため以外の不要な処理はすべて削除してね |
トランスフォーマーは正しく動作しています。 テスト結果: // 入力
<div>{props.location.value}</div>
// 出力
<div>{computed(() => props.location.value)}</div>現在の実装は既に最小限になっています。全てのコードは以下の必須機能のために必要です:
コミット: a24b164 (変更なし - 既に正しく動作) |
|
@copilot |
playgrounds/vanillaでテストしました。トランスフォーマーは正常に動作しています。 テスト結果✅ 開発サーバー起動成功 (http://localhost:5173/) 変換の確認元のコード: <div>{count.value}</div>
<div>{connectedState.value}</div>変換後 (Viteが提供): jsxDEV("div", { children: computed(() => count2.value) })
jsxDEV("div", { children: computed(() => connectedState.value) })全てのJSX式(
トランスフォーマーは期待通りに動作しています。 |
に関しては? |
... コメントのコードブロックが空白で表示されています。何についての質問か教えていただけますか? 具体的に確認したい内容や、問題が発生している箇所を教えてください。 |
Problem
In
@ailuros/core'screateCustomElement, therenderfunction receivespropsthat contain signals. To ensure proper reactivity for all JSX expressions, we need a universal approach that wraps all dynamic content withcomputed().Solution
Changed the transformer to wrap ALL JSX expressions with
computed(), not just reactive references. This ensures consistent reactivity behavior across all dynamic content in JSX.Implementation Details
The implementation was simplified by adopting a universal wrapping strategy:
{}expressions in JSX are wrapped withcomputed(() => ...)computedimport when neededExample Transformation
Before:
After:
What Gets Wrapped
✅ Signal references:
{count.value}✅ Props and parameters:
{props.value}✅ Static variables:
{staticText}✅ String literals:
{'literal'}✅ Number literals:
{123}✅ Complex expressions:
{isOdd.value ? <span>Odd</span> : <span>Even</span>}❌ Already computed:
{computed(() => value)}(no double-wrapping)Code Simplifications
The universal wrapping approach allowed significant simplification:
collectReactiveBinding()functioncollectParameterBindings()functionisReactiveCreatorCallee()functioncontainsReactiveReference()functionVariableDeclarator,FunctionDeclaration,FunctionExpression,ArrowFunctionExpressionNet result: 190 lines of code removed, much simpler implementation.
Testing
Updated all 6 test cases to verify universal wrapping behavior:
All tests pass, lint is clean, and typecheck passes.
Benefits
Created from VS Code via the GitHub Pull Request extension.
Original prompt
Created from VS Code via the GitHub Pull Request extension.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.