fix(types): correct BlockRule value type from any[] to PortableTextBlock#12509
fix(types): correct BlockRule value type from any[] to PortableTextBlock#12509
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🧪 E2E Preview environment🔑 Environment Variables for Local TestingThis is the preview URL for the E2E tests: https://e2e-studio-k5tx8ou8z.sanity.dev To run the E2E tests locally, you can use the following environment variables, then run 💬 Remember to build the project first with |
📊 Playwright Test ReportThis report contains test results, including videos of failing tests. |
📦 Bundle Stats —
|
| Metric | Value | vs main (d5c2b1c) | vs v5.18.0 |
|---|---|---|---|
| Internal (raw) | 4.37 MB | - | +27 B, +0.0% |
| Internal (gzip) | 1.00 MB | - | +3 B, +0.0% |
| Bundled (raw) | 12.04 MB | - | -36.1 KB, -0.3% |
| Bundled (gzip) | 2.71 MB | - | -6.3 KB, -0.2% |
| Import time | 1.56s | -4ms, -0.3% | +53ms, +3.5% |
Details
- Import time regressions over 10% are flagged with
⚠️ - Treemap artifacts are attached to the CI run for detailed size analysis
- Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
⚡️ Editor Performance ReportUpdated Wed, 25 Mar 2026 10:05:13 GMT
Detailed information🏠 Reference resultThe performance result of
🧪 Experiment resultThe performance result of this branch
📚 Glossary
|
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||
| marks?: BlockMarksDefinition | ||
| of?: ArrayOfType<'object' | 'reference'>[] | ||
| initialValue?: InitialValueProperty<any, any[]> | ||
| initialValue?: InitialValueProperty<any, PortableTextBlock> |
There was a problem hiding this comment.
The changes make sense, but is this actually valid?
I tried it and we surface an error when adding an initial value to the block definition.
I added this in AllTheBellsAndWhistles
defineArrayMember({
type: 'block',
name: 'block',
title: 'Block',
+ initialValue: {
+ style: 'normal',
+ _type: 'block',
+ _key: '123',
+ children: [
+ {
+ _type: 'span',
+ text: 'Hello, world!',
+ },
+ ],
+ },
Typescript validates it, but then the studio opens with an error:
# Schema errors
There were errors while attempting to compile the configuration of your Sanity Studio Schema types.
## Document type "pt_allTheBellsAndWhistles"
Path: pt_allTheBellsAndWhistles:document → fields → text:array → of → block:block
Error: Found unknown properties for block declaration: "initialValue"
## Document type "pt_allTheBellsAndWhistles"
Path: pt_allTheBellsAndWhistles:document → fields → text:array → of → block:block
Error: Found unknown properties for block declaration: "initialValue"
```
Description
Fixes #4464.
BlockRuleandBlockDefinitionusedany[]as their value type, but a block's runtime value is a singlePortableTextBlockobject - not an array. Every other schema type (StringRule,NumberRule,ObjectRule) uses its correct singular value type. This change makes block consistent.Backwards compatibility
This is a type-level breaking change by strict semver standards:
custom()validators on block types will now receivePortableTextBlockinstead ofany[]. In practice, the risk is low:any[]type was wrong - it never matched the runtime value. Anyone calling array methods based on this type already had a latent runtime bug.value?.filter(...)as if it were an array - confirming the type was incorrect, not that array usage was intended.What to review
BlockRulenowextends RuleDef<BlockRule, PortableTextBlock>instead ofRuleDef<BlockRule, any[]>BlockDefinition.initialValueandBlockDefinition.validationusePortableTextBlockinstead ofany[]PortableTextBlockand its constituent types (PortableTextTextBlock,PortableTextObject,PortableTextSpan,PortableTextChild,PortableTextListBlock) from@alphato@public- these types have been stable since September 2020 and are already widely used by consumersTesting
Notes for release
BlockRulenow usesPortableTextBlockinstead ofany[], matching the actual runtime value passed to custom validators.