Skip to content

feat(schema): support DEFAULT_PROPS export for default values#1118

Open
aka-sacci-ccr wants to merge 1 commit intomainfrom
aka-sacci-ccr/default-props-export
Open

feat(schema): support DEFAULT_PROPS export for default values#1118
aka-sacci-ccr wants to merge 1 commit intomainfrom
aka-sacci-ccr/default-props-export

Conversation

@aka-sacci-ccr
Copy link
Copy Markdown
Contributor

@aka-sacci-ccr aka-sacci-ccr commented Mar 13, 2026

Summary

  • Adds findExportedDefaultProps to extract export const DEFAULT_PROPS = { ... } from section/block AST
  • DEFAULT_PROPS takes priority over function parameter defaults when populating inputSchema.default
  • No changes needed on Admin side — it already reads definition.default

Example usage

export const DEFAULT_PROPS = {
  name: "Sacci",
  items: [{ title: "Item 1" }],
};

interface Props {
  name?: string;
  items?: { title: string }[];
}

export default function MinhaSection({ name = "fallback" }: Props) {
  return <div>Olá {name}</div>;
}

Priority: DEFAULT_PROPS export > function parameter default > nothing

Test plan

  • Verify sections with export const DEFAULT_PROPS get those values in inputSchema.default
  • Verify sections without DEFAULT_PROPS still use param defaults (no regression)
  • Verify Admin form pre-fills correctly with DEFAULT_PROPS values

🤖 Generated with Claude Code


Summary by cubic

Adds support for DEFAULT_PROPS exports in sections/blocks to define default values. These now take priority over function parameter defaults when setting inputSchema.default.

  • New Features
    • Added findExportedDefaultProps to read export const DEFAULT_PROPS = { ... } from the AST.
    • Priority: DEFAULT_PROPS > function parameter default > none.
    • No Admin changes needed; it already reads definition.default.

Written for commit 54b7e23. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Enhanced default property resolution for input object schemas with improved priority handling.

…values

Allow sections to export a `DEFAULT_PROPS` constant that takes priority
over function parameter defaults when generating the input schema.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 1.177.6 update
  • 🎉 for Minor 1.178.0 update
  • 🚀 for Major 2.0.0 update

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

A new helper function findExportedDefaultProps is introduced to extract module-level DEFAULT_PROPS objects from the AST. The programToBlockRef function is updated to establish a precedence for input schema defaults: exported DEFAULT_PROPS takes priority over function parameter defaults, with original defaultValue as fallback.

Changes

Cohort / File(s) Summary
Schema Default Priority Logic
engine/schema/transform.ts
Added findExportedDefaultProps helper function to locate and parse exported DEFAULT_PROPS from AST. Modified programToBlockRef to check for exported DEFAULT_PROPS first when determining input schema defaults, establishing a three-tier priority system.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops through schemas with glee,
Defaults now dance in priority,
DEFAULT_PROPS first, then param's delight,
Fallback stands ready, keeping things right!
One file transformed, logic refined,
Cleaner transformations, perfectly designed!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding support for DEFAULT_PROPS export as a source for default values in the schema transformation logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch aka-sacci-ccr/default-props-export
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="engine/schema/transform.ts">

<violation number="1" location="engine/schema/transform.ts:1537">
P2: `DEFAULT_PROPS` values that contain booleans are serialized as `null` because this path reuses a parser that does not handle `BooleanLiteral`.</violation>

<violation number="2" location="engine/schema/transform.ts:1614">
P2: Look up `DEFAULT_PROPS` in the resolved function module, not the entry module, so re-exported blocks keep their defaults.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

if (inputSchema.type === "object") {
inputSchema.default = defaultValue;
// Priority: DEFAULT_PROPS export > function parameter default > nothing
const exportedDefaultProps = findExportedDefaultProps(mProgram);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 13, 2026

Choose a reason for hiding this comment

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

P2: Look up DEFAULT_PROPS in the resolved function module, not the entry module, so re-exported blocks keep their defaults.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At engine/schema/transform.ts, line 1614:

<comment>Look up `DEFAULT_PROPS` in the resolved function module, not the entry module, so re-exported blocks keep their defaults.</comment>

<file context>
@@ -1584,7 +1610,9 @@ export const programToBlockRef = async (
     if (inputSchema.type === "object") {
-      inputSchema.default = defaultValue;
+      // Priority: DEFAULT_PROPS export > function parameter default > nothing
+      const exportedDefaultProps = findExportedDefaultProps(mProgram);
+      inputSchema.default = exportedDefaultProps ?? defaultValue;
     }
</file context>
Suggested change
const exportedDefaultProps = findExportedDefaultProps(mProgram);
const exportedDefaultProps = findExportedDefaultProps(parsedSource);
Fix with Cubic

decl.id.value === "DEFAULT_PROPS" &&
decl.init
) {
return generateObject(decl.init);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 13, 2026

Choose a reason for hiding this comment

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

P2: DEFAULT_PROPS values that contain booleans are serialized as null because this path reuses a parser that does not handle BooleanLiteral.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At engine/schema/transform.ts, line 1537:

<comment>`DEFAULT_PROPS` values that contain booleans are serialized as `null` because this path reuses a parser that does not handle `BooleanLiteral`.</comment>

<file context>
@@ -1516,6 +1516,32 @@ const getReturnFnFunction = async (
+          decl.id.value === "DEFAULT_PROPS" &&
+          decl.init
+        ) {
+          return generateObject(decl.init);
+        }
+      }
</file context>
Fix with Cubic

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@engine/schema/transform.ts`:
- Around line 1532-1538: The code currently treats any initializer for the
identifier DEFAULT_PROPS as an object by calling generateObject(decl.init);
update the conditional in the DEFAULT_PROPS branch to first verify the
initializer is an object literal (e.g., decl.init.type === "ObjectExpression" or
the project's AST equivalent) before calling generateObject, and skip/apply
no-default if it's not an object so inputSchema.default is not set to non-object
values; refer to the DEFAULT_PROPS identifier check and the
generateObject(decl.init) call when making this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: db5cb395-7cf1-4fbe-86ed-f1b34452f2f2

📥 Commits

Reviewing files that changed from the base of the PR and between b23d5b4 and 54b7e23.

📒 Files selected for processing (1)
  • engine/schema/transform.ts

Comment on lines +1532 to +1538
if (
decl.id.type === "Identifier" &&
decl.id.value === "DEFAULT_PROPS" &&
decl.init
) {
return generateObject(decl.init);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Validate DEFAULT_PROPS is an object literal before applying it.

Right now any initializer is accepted, so DEFAULT_PROPS can become a non-object default for an object schema. That can produce invalid inputSchema.default values.

Proposed fix
         if (
           decl.id.type === "Identifier" &&
           decl.id.value === "DEFAULT_PROPS" &&
           decl.init
         ) {
-          return generateObject(decl.init);
+          if (decl.init.type !== "ObjectExpression") {
+            continue;
+          }
+          const parsed = generateObject(decl.init);
+          if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
+            return parsed;
+          }
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (
decl.id.type === "Identifier" &&
decl.id.value === "DEFAULT_PROPS" &&
decl.init
) {
return generateObject(decl.init);
}
if (
decl.id.type === "Identifier" &&
decl.id.value === "DEFAULT_PROPS" &&
decl.init
) {
if (decl.init.type !== "ObjectExpression") {
continue;
}
const parsed = generateObject(decl.init);
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
return parsed;
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@engine/schema/transform.ts` around lines 1532 - 1538, The code currently
treats any initializer for the identifier DEFAULT_PROPS as an object by calling
generateObject(decl.init); update the conditional in the DEFAULT_PROPS branch to
first verify the initializer is an object literal (e.g., decl.init.type ===
"ObjectExpression" or the project's AST equivalent) before calling
generateObject, and skip/apply no-default if it's not an object so
inputSchema.default is not set to non-object values; refer to the DEFAULT_PROPS
identifier check and the generateObject(decl.init) call when making this change.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant