Skip to content

Conversation

@evilbocchi
Copy link
Owner

@evilbocchi evilbocchi commented Oct 22, 2025

Summary

  • add a disabledOptimizations transformer option that resolves hook and prop exclusions
  • propagate the configuration through the analyzer and transformer to force basic JSX handling when flagged
  • extend integration tests to cover hook-based bailouts and allow passing options to the harness

Testing

  • cd transformer && npm test

https://chatgpt.com/codex/tasks/task_e_68f88b0fd9d4832982aeecd49429117b

Summary by CodeRabbit

Release Notes

  • New Features

    • Added disabledOptimizations option to transformer configuration, enabling users to disable advanced optimizations for specific hooks, which will fall back to basic transforms.
    • Custom bailout properties are now configurable for JSX attribute analysis.
  • Refactor

    • Refactored optimization context to support conditional basic transform paths based on disabled optimization settings.

@coderabbitai
Copy link

coderabbitai bot commented Oct 22, 2025

Walkthrough

The changes introduce a configurable disabled optimizations feature allowing selective disablement of advanced optimizations for specific hooks and properties, alongside a customizable bailout property mechanism for JSX attribute analysis. Function context tracking enables hook-based disablement to force basic transforms, and a new conditional code path bypasses memoization when optimizations are disabled.

Changes

Cohort / File(s) Summary
Disabled Optimizations Framework
transformer/src/types.ts
Added DisabledOptimizationOptions and ResolvedDisabledOptimizationOptions types, resolveDisabledOptimizations utility, and isResolvedDisabledOptimizations type guard. Extended OptimizationContext with forceBasicTransformFunctions and disabledOptimizations fields.
Disabled Optimizations Framework
transformer/src/index.ts
Added disabledOptimizations option to DecillionTransformerOptions, introduced function stack tracking, hook-based disablement logic that forces basic transforms when disabled hooks are encountered, and helper utilities getCallExpressionIdentifier and getActiveFunctionName.
Disabled Optimizations Framework
transformer/src/transformer.ts
Updated DecillionTransformer constructor to accept and resolve disabledOptimizations, introduced shouldUseBasicTransform function for conditional basic transform path, and refactored transform methods to short-circuit to basic optimized element when disablement is active.
Bailout Property Customization
transformer/src/analyzer.ts
Added bailoutPropNames private field and customBailoutProps constructor parameter, merged default and custom bailout properties during initialization, replaced global BAILOUT_PROP_NAMES usage with instance field in JSX attribute analysis.
Integration Tests
transformer/test/transformer.integration.test.ts
Exposed DecillionTransformerOptions type, updated transformSource helper to accept optional options object, added test scenarios verifying disabled optimizations for specific hooks with assertions on output (presence of React.createElement, absence of createStaticElement and useFinePatchBlock).

Sequence Diagram

sequenceDiagram
    participant User
    participant Transformer
    participant BlockAnalyzer
    participant JSXTransformer
    
    User->>Transformer: transformCode(source, options)
    Transformer->>Transformer: resolveDisabledOptimizations(options)
    
    rect rgb(200, 220, 240)
    Note over Transformer: Setup & Scanning Phase
    Transformer->>Transformer: Create functionStack
    loop for each function node
        Transformer->>Transformer: push function to functionStack
        Transformer->>BlockAnalyzer: new BlockAnalyzer(..., customBailoutProps)
        BlockAnalyzer->>BlockAnalyzer: merge bailoutPropNames
    end
    end
    
    rect rgb(240, 200, 220)
    Note over Transformer: Hook Disablement Check
    loop for each hook call in function
        Transformer->>Transformer: Check if hook in disabledOptimizations
        alt Hook is disabled
            Transformer->>Transformer: Mark function in forceBasicTransformFunctions
        end
    end
    end
    
    rect rgb(220, 240, 200)
    Note over Transformer: JSX Transformation Phase
    Transformer->>JSXTransformer: transformJsxElement(element, context)
    alt shouldUseBasicTransform(context) = true
        JSXTransformer->>JSXTransformer: Return basic optimized element
    else Advanced optimization path
        JSXTransformer->>BlockAnalyzer: analyzeJsxElement(element)
        BlockAnalyzer->>BlockAnalyzer: Use bailoutPropNames for analysis
        JSXTransformer->>JSXTransformer: Apply memoization & fine-patch
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • types.ts & interfaces: Review new DisabledOptimizationOptions, ResolvedDisabledOptimizationOptions, and their integration into OptimizationContext; verify type guard logic
  • index.ts wiring: Trace function stack management, hook disablement detection, and parameter threading through multiple function calls
  • transformer.ts conditional logic: Verify shouldUseBasicTransform logic and its integration with existing transform paths; ensure both basic and advanced paths produce correct output
  • analyzer.ts bailout customization: Confirm proper merging of default and custom bailout properties; check JSX attribute analysis uses updated field consistently
  • Integration tests: Validate test coverage for disabled hook scenarios and verify expected output patterns

Poem

🐰 A rabbit's ode to optimizations fine,
Now bailout props align with thine design,
Disabled hooks yield basic transform's embrace,
While function stacks track every trace,
Customization hops through code with grace!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Add configurable optimization bailouts for hooks" is fully related to the main changes in this pull request. The PR introduces a disabledOptimizations transformer option that allows users to configure which hooks should not be optimized, which directly aligns with the concept of "configurable optimization bailouts for hooks." The title is clear, concise, and specific—it accurately captures the primary feature addition without noise. While the implementation also includes prop-based disablement (mentioned in DisabledOptimizationOptions), the title appropriately focuses on hooks as the primary use case, which is reflected in the test scenarios. A developer scanning the repository history would clearly understand that this PR adds the ability to configure which hooks should skip optimizations.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/make-framework-optimizations-configurable

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@evilbocchi evilbocchi marked this pull request as ready for review November 1, 2025 09:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fd48eb and 5d0ee7f.

📒 Files selected for processing (5)
  • transformer/src/analyzer.ts (3 hunks)
  • transformer/src/index.ts (6 hunks)
  • transformer/src/transformer.ts (6 hunks)
  • transformer/src/types.ts (2 hunks)
  • transformer/test/transformer.integration.test.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
transformer/src/analyzer.ts (1)
transformer/src/roblox-bridge.ts (1)
  • robloxStaticDetector (632-632)
transformer/test/transformer.integration.test.ts (1)
transformer/src/index.ts (1)
  • DecillionTransformerOptions (17-26)
transformer/src/transformer.ts (2)
transformer/src/types.ts (5)
  • DisabledOptimizationOptions (4-7)
  • ResolvedDisabledOptimizationOptions (9-12)
  • isResolvedDisabledOptimizations (41-50)
  • resolveDisabledOptimizations (14-39)
  • OptimizationContext (133-154)
transformer/src/roblox-bridge.ts (1)
  • robloxStaticDetector (632-632)
transformer/src/index.ts (3)
transformer/src/types.ts (2)
  • DisabledOptimizationOptions (4-7)
  • resolveDisabledOptimizations (14-39)
transformer/src/analyzer.ts (1)
  • BlockAnalyzer (23-719)
transformer/src/transformer.ts (1)
  • getFunctionName (1046-1072)

Comment on lines +96 to +108
if (ts.isCallExpression(node) && resolvedDisabledOptimizations.hooks.size > 0) {
const hookName = getCallExpressionIdentifier(node);
if (hookName && resolvedDisabledOptimizations.hooks.has(hookName)) {
const activeFunction = getActiveFunctionName(functionStack);
if (activeFunction) {
optimizationContext.forceBasicTransformFunctions.add(activeFunction);
if (debug) {
console.log(
`Disabling advanced optimizations for ${activeFunction} due to hook ${hookName}`,
);
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Hook bailouts miss anonymous components

We only ever push function names onto functionStack, so getActiveFunctionName returns undefined for anonymous functions (e.g. export default () => { useContext(...) }). That means the new hook-based bailout never trips for those components, and advanced optimizations still run even though useContext is in disabledOptimizations.hooks. This breaks the main feature for a very common pattern. Please track the actual function nodes (or another unique identifier) instead of just names when pushing/popping, and store those identifiers in forceBasicTransformFunctions so anonymous/default exports are covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants