fix(js/ts): Fix JSX props with long string values causing compile error (fixes #3839)#4545
Merged
MangelMaxime merged 2 commits intomainfrom Apr 21, 2026
Conversation
41 tasks
) When a JSX prop's string value exceeds ~100 characters, Fable wraps it in a Let binding. The transformJsxProps function only matched the direct Value(NewTuple([key; value])) pattern, causing a 'Cannot detect JSX prop key at compile time' error for any string longer than the threshold. Fix: add a match arm for MaybeCasted(Let(_, letValue, Value(NewTuple(...)))) to extract the key from the tuple body and use the Let-bound value as the prop value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> chore: revert CHANGELOG.md
7b98fdb to
0e97261
Compare
This was referenced Apr 21, 2026
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.
🤖 This is a draft PR from Repo Assist, an automated AI assistant.
Closes #3839
Root Cause
When a JSX prop's string value exceeds ~100 characters, Fable optimises the Fable AST by hoisting the string into a
Letbinding. The resulting expression changes from:The
transformJsxPropsfunction inFable2Babel.fsonly matched the directMaybeCasted(Value(NewTuple([key; value], ...), ...))pattern. When the string was Let-wrapped, no arm matched and the fallthroughaddErrorfired with "Cannot detect JSX prop key at compile time".Fix
Added a new match arm in
transformJsxPropsthat handlesMaybeCasted(Let(_, letValue, Value(NewTuple([key; _], ...), ...))). In this pattern:letValueis the actual long string value (what was bound)keyis the prop name, extracted from inside the Let body's tuple_inside the tuple is theIdentExprreference to the Let-bound variable (not needed)The fix correctly uses
letValueas the prop value, exactly as if the string had been written inline.Test
Added
divWithLongClassNameto the JSX integration test inComponents.fswith a string of 98 'a' characters (above the ~100-char threshold), and the corresponding expected output toComponents.jsx.expected.Trade-offs
Fable2Babel.fs(the JS/TS code generator) is modifiedchildrenprop with a long string value is also handled correctly in the new arm