Gatsby to Astro: Why I Finally Migrated

• 3 min read

This site started in 2017 and sat on Gatsby 2.28.2 for years. React 16, Ant Design v3, D3 v5. Security warnings kept piling up, and builds were slow.

I kept putting it off. Last week I finally moved 22 articles and 14 data visualizations to Astro 4.x.

Why Astro

I looked at Next.js, Remix and Astro. This is a content site with a few interactive charts, so Astro fit:

  • Zero JS by default. A page ships HTML unless a component asks for more.
  • Islands. Only the interactive components hydrate.
  • Keeps React. I didn’t have to rewrite my components.

The migration

Markdown was easy

Six articles were plain markdown. A small script rewrote the frontmatter:

# Gatsby                      # Astro
written: "2018-10-02"         date: 2018-10-02
category: "Deep Learning"     tags: ["Deep Learning"]

Those moved in minutes.

React pages took longer

The other 16 articles were React pages with charts, API calls and interactivity. I turned each one into MDX and loaded the components with client directives:

import VegaChart from '@/components/VegaChart.tsx';

<VegaChart client:visible specUrl="..." />

client:visible only loads the JS when the chart scrolls into view.

Ant Design had to go

Ant Design v3 was the heaviest dependency. I replaced it with Tailwind. More work up front, but the bundle got much smaller.

Charts needed rewiring

Plotly and Vega didn’t hydrate cleanly, so I moved most charts to ECharts via echarts-for-react.

Gotchas

The ones worth knowing before you start:

  • Old service workers. Gatsby registered a service worker. It stayed in readers’ browsers after the switch and kept asking for page-data/*.json files that no longer exist. Result: blank blog posts. The fix is a small script that unregisters old workers.
  • public/ was gitignored. Local builds worked. Netlify builds had no images.
  • _headers lives in public/, not the repo root.
  • Raw echarts.init() doesn’t play well with React hydration. Use the React wrapper.
  • react-scrollama breaks in Astro. A plain IntersectionObserver works.
  • vis-network has CommonJS issues with Vite.

Results

MetricGatsbyAstro
First Contentful Paint~2.5s~0.5s
JS bundle~300KB~30KB
Lighthouse Performance6095

What I’d do differently

Keep the old site running next to the new one. I worked in a separate directory, which made side-by-side comparison easy. I’d do that again, from day one.

Don’t rewrite what works. If a React component works, keep it as React. Astro is happy to mix.

Hand off the boring parts. Claude Code did the bulk frontmatter conversion and found the broken image paths. The repetitive parts went fast.

Worth it?

Yes. The site is faster, and I no longer dread dependency updates. I should have done it sooner.

If you’re stuck on an old Gatsby, Astro is a good fit for a content site. The move isn’t trivial, but it’s worth it.


References

[1] Astro documentation