#new features
20 messages · Page 1 of 1 (latest)
Hi @bold spoke. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Absolutely! Astro has introduced several powerful features in recent versions, with the Islands Architecture being one of the most significant. Here’s a summary of the newest features and how they work, based on the latest official documentation:
1. Islands Architecture
Astro pioneered the Islands Architecture, which is all about rendering most of your page as fast, static HTML, and only adding JavaScript to small, interactive “islands” where needed. This approach avoids the heavy JavaScript payloads common in traditional single-page applications (SPAs), resulting in much faster load times and better SEO.
-
Client Islands: These are interactive components (like a carousel or a menu) that are hydrated on the client only when needed. You mark them with a
client:*directive, such asclient:load,client:idle, orclient:visible, to control when the JavaScript loads.<!-- Example: React component becomes interactive only when loaded --> <MyReactComponent client:load />The rest of your site remains static and fast, while only the marked components get the necessary JavaScript for interactivity. This selective hydration is the secret to Astro’s performance advantage Islands architecture.
-
Server Islands: These allow you to defer server-side rendering of dynamic or personalized content until it’s needed, without blocking the rest of the page. You use the
server:deferdirective on Astro components.---import Avatar from "../components/Avatar.astro";--- <Avatar server:defer />You can also provide fallback content that displays while the server island is loading:
<Avatar server:defer> <GenericAvatar slot="fallback" /> </Avatar>
This is great for things like user avatars, personalized deals, or user reviews—your main content loads instantly, and dynamic parts load in parallel Server islands.
2. UI-Agnostic and Multi-Framework Support
Astro now supports multiple UI frameworks in the same project, including React, Preact, Svelte, Vue, and SolidJS. You can mix and match frameworks as needed, even on the same page, which is great for gradual migrations or using the best tool for each component Island components.
3. Content Collections
Astro introduced content collections for organizing and validating your Markdown content with automatic TypeScript type-safety. This makes it easier to manage blogs, documentation, and other content-heavy sites Why Astro?.
4. View Transitions
Astro now supports view transitions for seamless page transitions and animations, enhancing the user experience without heavy client-side routing Next Steps.
5. Experimental Features and Upgrades
Astro frequently introduces experimental features behind flags, allowing you to try out new capabilities before they become stable. In recent major versions (v3 and v5), many experimental features like view transitions, server islands, and enhanced image services have become stable and are now enabled by default. You no longer need to enable them manually in your config Configuring experimental flags, Upgrade to Astro v5.
In summary:
Astro’s newest features focus on performance, flexibility, and developer experience. The Islands Architecture (client and server islands) is the standout, letting you build fast, content-driven sites with just the right amount of interactivity. You can now use multiple frameworks, manage content more safely, and add smooth transitions—all with minimal JavaScript by default.
If you want to dive deeper, check out the Islands Architecture documentation and the official Astro recipes for practical examples.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@bold spoke Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@neat vector I’m building a statically generated website with Astro, using Sanity as my CMS. I want to add a simple newsletter signup form inside a modal. When a user submits their email, I want to store it (e.g. in Sanity or elsewhere), then show a success message without reloading the page.
I also want to display a live counter on the homepage showing how many people subscribed today (or yesterday, if today is low).
Later, I’ll use the email list to send a designed newsletter (HTML/CSS, with animations/GIFs) once per quarter but not yet so ignore that
Given this setup, what’s the best way to implement this in Astro with the latest features if applicable?
Let me check the knowledge base for you again. One moment! :books:
To implement a statically generated Astro site with a modal newsletter signup form, live subscriber counter, and a smooth, no-reload user experience, you can leverage Astro’s latest features and best practices as follows:
1. Newsletter Signup Form (No Page Reload)
Astro recommends handling interactive forms using a UI framework component (React, Vue, Svelte, etc.) as a client island. This allows you to intercept the form submission with JavaScript, send the data to an API endpoint, and display a success message—all without reloading the page.
Example (React, but works similarly with other frameworks):
import { useState } from "react";
export default function NewsletterForm() {
const [responseMessage, setResponseMessage] = useState("");
async function submit(e) {
e.preventDefault();
const formData = new FormData(e.target);
const response = await fetch("/api/newsletter", {
method: "POST",
body: formData,
});
const data = await response.json();
setResponseMessage(data.message);
}
return (
<form onSubmit={submit}>
<input type="email" name="email" required />
<button>Subscribe</button>
{responseMessage && <p>{responseMessage}</p>}
</form>
);
}
Then, in your Astro page:
---import NewsletterForm from "../components/NewsletterForm";---
<NewsletterForm client:load />
This ensures the form is interactive, but the rest of your site remains static and fast Build forms with API routes.
2. API Endpoint for Submissions
Create an API route (e.g., /api/newsletter.ts) to receive and process the form data. You can validate and store the email here (e.g., send it to Sanity or another service).
export const prerender = false; // Not needed in 'server' mode
import type { APIRoute } from "astro";
export const POST: APIRoute = async ({ request }) => {
const data = await request.formData();
const email = data.get("email");
// TODO: Store email in Sanity or another backend
if (!email) {
return new Response(JSON.stringify({ message: "Missing email" }), { status: 400 });
}
return new Response(JSON.stringify({ message: "Success!" }), { status: 200 });
};
3. Live Subscriber Counter
For a live counter, you’ll need a way to fetch the current count from your backend (Sanity or another store). Create another API endpoint (e.g., /api/subscriber-count) that returns the count for today or yesterday. On the homepage, use a client island to fetch and display this count.
Example (React):
import { useEffect, useState } from "react";
export default function SubscriberCounter() {
const [count, setCount] = useState(null);
useEffect(() => {
fetch("/api/subscriber-count")
.then(res => res.json())
.then(data => setCount(data.count));
}, []);
return <div>Subscribers today: {count ?? "Loading..."}</div>;
}
And in your Astro page:
---import SubscriberCounter from "../components/SubscriberCounter";---
<SubscriberCounter client:load />
4. Modal Implementation
You can use your UI framework’s modal component, or a simple custom modal, and place the newsletter form inside it. The modal logic itself can be handled in the same client island.
5. Summary of Astro Features Used
- Client Islands: Only hydrate the interactive form and counter, keeping the rest of the site static and fast.
- API Routes: Handle form submissions and provide live data for the counter.
- No Page Reloads: All user interactions are handled client-side for a smooth UX.
Note:
The knowledge sources do not provide direct integration details for Sanity, but the pattern above is fully supported by Astro’s latest features and is the recommended approach for interactive forms and live data on a statically generated site Build forms with API routes, Client Islands.
If you need to store emails in Sanity, you’ll need to implement that logic in your API route using Sanity’s API.
Let me know if you want a more detailed code example for a specific framework or more info on integrating with Sanity!
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@bold spoke Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@neat vector oh but whats the advantage of using react or other framework? Can't I just do it in vanilla js?
Let me check the knowledge base for you again. One moment! :books:
Yes, you can absolutely use vanilla JavaScript for interactivity in Astro! Astro allows you to add client-side scripts directly to your components using standard HTML <script> tags. This is a great option for simple interactions, such as handling form submissions or button clicks, without the need for a UI framework like React, Svelte, or Vue.
Example: Adding interactivity with vanilla JS in Astro
<button data-confetti-button>Celebrate!</button>
<script>
// Import npm modules.
import confetti from 'canvas-confetti';
// Find our component DOM on the page.
const buttons = document.querySelectorAll('[data-confetti-button]');
// Add event listeners to fire confetti when a button is clicked.
buttons.forEach((button) => {
button.addEventListener('click', () => confetti());
});
</script>
This approach is simple and keeps your site lightweight, as you don’t need to include a framework’s runtime or bundle extra JavaScript unless your needs grow more complex Scripts and event handling.
When to use a framework?
Frameworks like React, Svelte, or Vue become helpful when your UI logic gets more complex—such as managing component state, handling complex forms, or building reusable interactive widgets. They provide a more declarative and maintainable way to build UIs, especially as your project grows Building apps with a UI framework.
But for simple forms and modals, vanilla JS is perfectly fine in Astro!
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@bold spoke Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@neat vector Okay and but if I understand it correctly like for my needs right now there's it makes no sense to use like the latest features like um like island architecture or like server islands or stuff like that and in what use cases are these like necessary or like interesting like maybe in link to what I do like when could it become interesting to use them you know?
Let me check the knowledge base for you again. One moment! :books:
You’re correct: for a simple newsletter signup form and a live counter, you don’t have to use Astro’s islands architecture or server islands. You can achieve your goals with vanilla JavaScript and standard Astro components, keeping things lightweight and simple Checklist: Use JavaScript for interactivity when you don’t want to add a framework.
When do islands become interesting or necessary?
-
Client Islands are useful when you want to add interactive widgets (like a live counter, carousel, or complex form) that require a UI framework (React, Svelte, etc.) or more advanced state management. They let you hydrate only those components, keeping the rest of your site static and fast. For example, if your newsletter modal became a multi-step form with validation, or you wanted to reuse it across many pages, a client island could help Client Islands.
-
Server Islands are valuable when you need to render dynamic or personalized content on the server, but don’t want to delay the main page load. For example, if you wanted to show a user’s profile info, personalized deals, or live data that’s fetched server-side, you could use a server island to load just that part of the page on demand, with fallback content shown instantly Server islands.
In your current use case:
- If your form and counter are simple, vanilla JS is enough.
- If you later want more complex interactivity, or need to mix static and dynamic/personalized content without slowing down your site, islands architecture becomes very useful.