fix(create-ui): parse JSON callback data to extract component code#69
Open
fuleinist wants to merge 1 commit into
Open
fix(create-ui): parse JSON callback data to extract component code#69fuleinist wants to merge 1 commit into
fuleinist wants to merge 1 commit into
Conversation
Author
|
LGTM — the fix is clean and well-scoped. The JSON.parse in a try/catch with fallback to raw string handles all three cases (component field, text field, non-JSON string) correctly. The 6 new tests cover the edge cases thoroughly. One minor nit: the test file is missing a trailing newline (EOF). Ready to merge. |
Author
|
Spotted a minor nit from self-review: the test file is missing a trailing newline at EOF. Trivial one-liner — can be fixed by adding a blank line at the end of src/tools/create-ui.test.ts. Since I can't push to this branch directly (no write access to 21st-dev/magic-mcp), leaving this note for whoever merges: just add a final newline to the file before merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
21st_magic_component_buildertool was returning[object Object]instead of the actual component TSX code when called from Claude Code.Problem
The callback server receives component data as a JSON string (e.g.
{"component": "export function Button()..."}) and passes it through as-is. Theexecute()method was using the raw string directly asprompt, causing JavaScript to convert the JSON string to[object Object]when embedded in the response template.Solution
Parse the callback data as JSON and extract the
componentortextfield:componentortextTesting
src/tools/create-ui.test.tscomponentfieldtextfieldFiles Changed
src/tools/create-ui.ts- JSON parsing fix for callback datasrc/tools/create-ui.test.ts- unit tests for callback data parsingFixes #68