jaspr-pre-rendering-and-hydration

Enforce hydration and import rules for Jaspr SSR/SSG apps.

803|85|Updated Nov 18, 2023
One-click install
npx skills add https://github.com/rodydavis/signals.dart --skill jaspr-pre-rendering-and-hydration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jaspr-pre-rendering-and-hydration
Source: https://github.com/rodydavis/signals.dart/tree/main/.agents/skills/jaspr-pre-rendering-and-hydration
Command: npx skills add https://github.com/rodydavis/signals.dart --skill jaspr-pre-rendering-and-hydration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you structure Jaspr apps for static or server rendering so interactive behavior is correctly enabled through hydration, without runtime crashes or invalid imports.

Core Features & Use Cases

  • Dual entrypoints (server vs client): Separate server rendering from client interactivity using main.server.dart and main.client.dart.
  • SSR/SSG import safety: Prevent invalid platform-specific imports by enforcing server-only and client-only library rules.
  • Hydration with @client: Enable browser interactivity by annotating only the uppermost component that needs it, while hydrating a whole subtree.
  • Safe data passing to @client components: Ensure parameters are initialization fields and fully serializable across the server-to-browser boundary.
  • Server async rendering: Fetch data during build using server-only async components, then pass results into hydrated client components.

Quick Start

Apply the dual-entrypoint rules for your Jaspr mode in pubspec.yaml, annotate only the topmost interactive component with @client, and pass server-fetched serializable data into that component as initializing parameters.

Frequently Asked Questions about jaspr-pre-rendering-and-hydration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up Jaspr hydration for SSR or SSG without runtime crashes?

To set up Jaspr hydration safely, use dual entrypoints like main.server.dart and main.client.dart, and annotate only the topmost interactive component with @client. This separates server rendering from browser interactivity and prevents invalid platform imports.

Why does my @client component break when passing server-fetched data in Jaspr?

Your @client component breaks because parameters must be fully serializable across the server-to-browser boundary. Ensure all data passed into hydrated client components are initialization fields that can safely serialize during static or server rendering.

How do I prevent browser APIs from running during Jaspr pre-rendering?

To prevent browser APIs from running during Jaspr pre-rendering, enforce server-only and client-only library import constraints. This ensures browser interactivity code runs exclusively in the client while server-only code runs during pre-rendering.

Can I fetch data asynchronously during Jaspr server-side rendering?

Yes, you can fetch data asynchronously during Jaspr server-side rendering by using server-only async components. Fetch data during the build phase and pass the serializable results into hydrated client components as initializing parameters.

What is the best way to structure a Jaspr app for static site generation?

The best way to structure a Jaspr app for static site generation is defining dual entrypoint files in pubspec.yaml, applying @client only to the highest interactive component, and maintaining strict import safety for server-only and client-only libraries.