#468
fix(core): check props per component in multi-component catalogs
Fixes #378, also reported as #467.
- With two or more components, the
propsOffield in the spec schema was a permissivez.record(z.string(), z.unknown()), socatalog.validate()andcatalog.zodSchema()accepted any props. A one-component catalog did check them. - When an object pairs a
propsOffield with exactly onereffield to the same catalog path (propswithtypein the renderer schemas,propswithcomponentin remotion), the element is now checked with asuperRefineagainst the entry the ref selects. Issues keep zod's codes and are reported under the props path, for example["elements", "t", "props", "content"], the same as a one-component catalog. - The schema shape stays the same, so
catalog.jsonSchema()output (strict or not) does not change. A test compares it with an open-props schema. - Catalogs with one entry, and
propsOffields with no matchingref(or more than one), keep the current behavior. getKeysFromPathandgetPropsFromPathnow share a smallgetEntriesFromPathhelper.
Things to be aware of:
- Specs for multi-component catalogs that passed before can now fail. This includes props that still hold unresolved expressions such as
{ "$state": "/x" }in a field typedz.string(), which a one-component catalog already rejects today.experimental-composeresolves props before callingvalidate(), so it is not affected. If you would rather havevalidate()let expressions through, I can change that, but it would also change the one-component behavior. - Only the pass or fail result is per component.
result.data.propsis still the input props, so with several components unknown keys are kept and zod defaults and transforms are not applied, as before. - As with one component, a props schema with async refinements throws from the synchronous check.
- When an element has another issue (for example missing
children), zod skips refinements, so its props issues show up once that issue is fixed.
The chat renderer validates props itself because of this gap (noted in #451); that code can stay as is.
@TanmayShah29 is attempting to deploy a commit to the Vercel Labs Team on Vercel.
A member of the Team first needs to authorize it.