Hi :wave: I’m having a problem with v3. I get the an uncaught error saying “crop” is read-only in the block editor when there are image with crop&hotspot.
Error: "crop" is read-only
Error Analysis: "crop" is read-only in Block Editor (v3) with Image Crop & Hotspot
The error message "crop" is read-only in the context of the Sanity Block Editor (v3) when dealing with images that have crop and hotspot settings suggests a compatibility or configuration issue. Given that you're using the latest v3 and have searched through existing discussions (referencing an abandoned issue from summer), here's a step-by-step approach to resolve or further troubleshoot the problem:
1. Verify Schema Configuration
Ensure your image field in the schema allows for mutations on the crop property. Sometimes, unintentional schema constraints can lead to read-only behaviors. Check your schema definition for the image field, specifically looking for any overrides or custom configurations that might set crop as read-only. A common pitfall is accidentally setting readOnly: true in the schema, which can cause this error.
Action: Review your schema file (usually found in schemas directory, e.g., image.schema.js). Look for any crop property definitions and verify if there's a readOnly flag set to true. Ensure it matches the structure recommended in Sanity's documentation for image fields.
2. Check for Plugin Versions
Though you mentioned using the latest v3, it's crucial to ensure all related plugins (e.g., @sanity/image-url, @sanity/preview) are up-to-date, as compatibility issues can arise from version mismatches. Known issues in previous versions of Sanity might have caused similar problems, so updating can resolve this.
Action: Run npm outdated or yarn outdated to identify any outdated packages. Update any outdated Sanity-related packages to their latest versions. You can refer to the Sanity changelog to see if recent updates address read-only issues.
3. Inspect Block Editor Configuration
The Block Editor's behavior can be influenced by its configuration. Review how the image block is defined within your editor setup, ensuring there aren't any overrides making crop read-only. Custom configurations, especially those related to image processing, might inadvertently restrict editing capabilities.
Action: Examine your Block Editor configuration files (usually in deskStructure or where you define custom blocks) for any crop property overrides on image blocks. Ensure these align with Sanity's Block Editor documentation for customizing image blocks.
4. Reproduce with Minimal Setup
To isolate the issue, try reproducing it with a minimal setup:
* Create a new, simple schema for an image with crop and hotspot.
* Use this schema in a basic Block Editor setup.
* Attempt to edit the image's crop settings.
Action: If the issue persists, share this minimal reproduction setup on GitHub or a similar platform for the community or Sanity support to inspect more closely. This will help identify if the problem is specific to your configuration or a broader issue with Sanity v3.
5. Engage with the Community & Support
Given the abandoned issue you found, it might be beneficial to:
* Revive the discussion on GitHub with your findings, especially if you've managed to reproduce the issue in a minimal setup. Provide detailed steps and code snippets to help others understand the problem.
* Reach out to Sanity's support with your detailed troubleshooting steps and outcomes for personalized assistance. Mention any known issues or recent changes in Sanity's API that might be relevant.
Action: Share your experience and the steps you've taken in the GitHub discussion and/or when contacting Sanity support. Use the Sanity community forums or GitHub discussions to engage with developers who may have encountered similar issues.
Example Schema Reference (for step 1)
To illustrate, here's a basic image schema where crop is intentionally set to read-only. Ensure your setup doesn't have a similar constraint:
javascript
export default {
name: 'image',
type: 'image',
fields: [
{
name: 'asset',
type: 'reference',
to: { type: 'sanity.imageAsset' },
},
{
name: 'crop',
type: 'imageCrop',
// **REMOVE OR SET TO FALSE IF PRESENT**
// readOnly: true,
},
// ... other fields
],
}
Hope this detailed troubleshooting guide helps you resolve the "crop" is read-only error in the Sanity Block Editor (v3). If not, the community and Sanity support are your next best steps.