Skip to content

feat(android): warn when layout child limits are exceeded#228

Open
V3RON wants to merge 2 commits into
mainfrom
feat/dev-validate-hook
Open

feat(android): warn when layout child limits are exceeded#228
V3RON wants to merge 2 commits into
mainfrom
feat/dev-validate-hook

Conversation

@V3RON

@V3RON V3RON commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What is this?

This PR adds a dev-only validate hook for Voltra components and uses it to warn when Android Column or Row receive more than 10 direct children — the hard limit imposed by Jetpack Glance, which silently truncates anything beyond it. Until now, exceeding the limit produced no feedback at all: the widget just dropped children at runtime with no hint as to why.

How does it work?

createVoltraComponent accepts a new optional validate callback. It is stored on the component and invoked by the renderer — not at element creation time, where children are still raw JSX (fragments, arrays, conditionals), but at node-assembly time, once children have been recursively rendered and fully flattened. That means the count the validator sees is exactly the number of children the native side will receive.

export const Column = createVoltraComponent<ColumnProps>('AndroidColumn', {
  validate: ({ children }) => {
    if (children.length > 10) {
      console.warn(`Column supports at most 10 direct children in Jetpack Glance, got ${children.length}. ...`)
    }
  },
})

The hook only runs in development — gated on __DEV__ in Metro bundles and process.env.NODE_ENV in Node.js (the renderer runs in both) — and never affects the rendered JSON. Column and Row now warn past 10 children, and the layout components docs mention the limit with a pointer to LazyColumn for larger collections.

Why is this useful?

  • Turns a silent native-side truncation into an actionable dev-time warning, at the exact child count Glance will see (fragments and conditionals already resolved).
  • Zero production overhead — validation is compiled around a dev check and adds no allocations or traversals to the render path.
  • Gives every platform package a place to declare per-component constraints (validate on createVoltraComponent), so future Glance/WidgetKit limits can be enforced the same way.
  • Documents the Glance limit where users will look for it, on the Column and Row docs.

Closes #220

Adds a dev-only validate hook to createVoltraComponent, invoked by the
renderer once children are fully flattened (fragments inlined, nulls
dropped). AndroidColumn and AndroidRow use it to warn when more than 10
direct children are rendered, matching the Jetpack Glance limit. Docs
updated with the limit on the layout components page.
@V3RON V3RON changed the title feat: warn in dev when Column/Row exceed Glance 10-child limit feat(android): warn when layout child limits are exceeded Jul 14, 2026
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.

Problem rendering all elements

1 participant