Updates and Upgrades
Keeping your Sanityblocks project updated ensures you have access to the latest features, bug fixes, and improvements. This guide covers the recommended approach for managing updates while preserving your customizations.
Fork-Based Update Strategy
We recommend starting your project by forking the Sanityblocks repository rather than cloning it directly. This approach provides the cleanest path for receiving updates while maintaining your customizations.
Benefits of Forking
- Clean merge process: Minimize conflicts when pulling updates
- Version control: Track your customizations separately from upstream changes
- Selective updates: Choose which updates to apply and when
- Backup safety: Your fork serves as a backup of your customizations
Initial Setup
1. Fork the Repository
- Visit the Sanityblocks repository on GitHub
- Click the Fork button in the top-right corner
- Choose your GitHub account as the destination
- Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/sanityblocks.gitcd sanityblocks
2. Add Upstream Remote
Add the original Sanityblocks repository as an upstream remote to fetch updates:
git remote add upstream https://github.com/serge-0v/sanityblocks.git
Verify your remotes are set up correctly:
git remote -v
You should see:
origin https://github.com/YOUR_USERNAME/sanityblocks.git (fetch)origin https://github.com/YOUR_USERNAME/sanityblocks.git (push)upstream https://github.com/serge-0v/sanityblocks.git (fetch)upstream https://github.com/serge-0v/sanityblocks.git (push)
Receiving Updates
1. Fetch Latest Changes
Before updating, fetch the latest changes from the upstream repository:
git fetch upstream
2. Check for Updates
View what’s changed since your last update:
git log HEAD..upstream/main --oneline
This shows commits you haven’t merged yet.
3. Merge Updates
There are two approaches for merging updates:
Option A: Merge Commit (Recommended)
Creates a merge commit that clearly shows when updates were applied:
git checkout maingit merge upstream/main
Option B: Rebase (Advanced)
Replays your changes on top of the latest updates:
git checkout maingit rebase upstream/main
Note: Only use rebase if you understand Git well and haven’t pushed your changes yet.
4. Resolve Conflicts
If conflicts occur during merging:
- Review conflict files: Git will mark conflicted files
- Edit conflicted files: Choose which changes to keep
- Mark as resolved: Run
git add <filename>
for each resolved file - Complete the merge: Run
git commit
(for merge) orgit rebase --continue
(for rebase)
Common Conflict Scenarios
Most conflicts will occur in these areas:
- Custom block additions: Your custom blocks vs. new upstream blocks
- Package.json: Dependency version differences
- Configuration files: Environment or build configuration changes
- Generated files:
studio/schema.json
andfrontend/sanity.types.ts
Generated Files - Don’t Resolve Manually
Two files that commonly show conflicts during updates should never be resolved manually:
studio/schema.json
- Auto-generated file containing compiled Sanity schema definitions
- Created by running
pnpm typegen
or Sanity CLI commands - Contains serialized versions of all your schema types
frontend/sanity.types.ts
- Auto-generated TypeScript definitions based on your Sanity schemas
- Provides type safety between Sanity content and React components
- Created by the Sanity TypeScript code generation
How to Handle These Files During Conflicts
❌ Don’t do this:
# Don't manually edit these files during merge conflictsgit add studio/schema.jsongit add frontend/sanity.types.ts
✅ Do this instead:
# Remove the conflicted generated filesgit rm studio/schema.jsongit rm frontend/sanity.types.ts
# Complete the mergegit commit
# Regenerate the filespnpm typegen
Why this approach works:
- Generated files will always reflect your current schema state
- Avoids invalid/corrupted type definitions
- Ensures consistency between schema and TypeScript types
- Prevents runtime errors from mismatched types
Best Practices for Minimal Conflicts
Follow these guidelines to reduce merge conflicts:
1. Use Custom Naming Convention
Always suffix your customizations with -custom
:
// ✅ Good - Safe from future conflictsexport default defineType({ name: "hero-14-custom", title: "Hero 14 Custom", // ...});
// ❌ Avoid - Will conflict if we release hero-14 laterexport default defineType({ name: "hero-14", title: "Hero 14", // ...});
2. Keep Customizations Separate
- Don’t modify existing files: Copy and rename instead
- Create new directories: For completely new block categories
- Use dedicated custom folders: Group your customizations together
3. Document Your Changes
Maintain a CUSTOM_CHANGES.md
file documenting your modifications:
# Custom Changes
## Custom Blocks Added
- `hero-12-custom`: Custom hero with additional CTA field- `testimonial-carousel`: New testimonial block with carousel
## Modified Files
- `frontend/components/blocks/index.tsx`: Added custom block imports- `studio/schema.ts`: Added custom schemas
## New Dependencies
- `swiper`: Added for carousel functionality
Update Checklist
When applying updates, follow this checklist:
Pre-Update
- Commit your changes: Ensure your work is saved
- Create a backup branch:
git checkout -b backup-before-update
- Test current state: Ensure everything works before updating
- Review release notes: Check what’s changed in the update
During Update
- Fetch upstream changes:
git fetch upstream
- Review changes:
git log HEAD..upstream/main --oneline
- Merge updates:
git merge upstream/main
- Resolve conflicts: Address any merge conflicts carefully
- Update types: Run
pnpm typegen
after schema changes
Post-Update
- Install dependencies:
pnpm install
for any new packages - Test functionality: Verify both frontend and studio work
- Check custom blocks: Ensure your customizations still work
- Update documentation: Note any changes to your custom setup
- Deploy: Push changes to your deployment
Troubleshooting Updates
Large Number of Conflicts
If you encounter many conflicts:
- Reset and start over:
git merge --abort
- Review your customizations: Consider if they follow best practices
- Apply updates incrementally: Merge smaller ranges of commits
Broken Functionality After Update
If something breaks after updating:
- Check console errors: Look for TypeScript or runtime errors
- Regenerate types: Run
pnpm typegen
- Clear cache: Clear Next.js and dependency caches
- Review schema changes: Check if field names or structures changed
- Test in isolation: Create a minimal reproduction of the issue
Reverting Updates
If you need to undo an update:
# Find the merge commitgit log --oneline -n 10
# Revert the merge (replace HASH with actual commit hash)git revert -m 1 HASH
# Or reset to previous state (loses changes!)git reset --hard HEAD~1
Advanced Update Strategies
Update Branches
Create dedicated branches for testing updates:
git checkout -b test-updatesgit merge upstream/main# Test everything worksgit checkout maingit merge test-updates
Remember: Following the Custom Blocks best practices significantly reduces update conflicts and makes the process smoother.