Jaspr Framework Documentation

repository·main·Indexed 25 days ago

https://github.com/schultek/jaspr

Jaspr is a fullstack Dart web framework that provides a Flutter-like developer experience while rendering native HTML and CSS. It supports SSR, CSR, and SSG for building high-performance, SEO-friendly websites. The framework includes a CLI for serving and building projects, a VS Code extension (jaspr-code) for project scaffolding and debugging, and integration capabilities with backends like Serverpod, Dart Frog, and Shelf. It also supports Flutter element embedding and Riverpod state management via jaspr_riverpod.

Tokens
122.8K
Snippets
417
Records
623
Agent score
81%

What's inside Jaspr

  1. Overview of Jaspr API Categories

    main

    The Jaspr API is organized into three main functional areas:

    1. Components: UI building blocks including document structure, routing, styling, and specialized components like RawText or FlutterEmbedView.
    2. General: Core utilities for running the application, type-safe CSS styling, event bindings, and DOM access.
    3. Server / Client: Tools for managing the boundary between server-side rendering and client-side hydration, including annotations for data synchronization, state preloading, and handling HTTP headers/cookies.
  2. Overview of jaspr_content

    main

    jaspr_content is a first-party Jaspr package designed for building content-driven websites such as documentation sites, blogs, or marketing pages. It provides tools for loading, parsing, and rendering content from sources like Markdown files, while remaining fully customizable through user-provided implementations.

    Key capabilities include:

    • Markdown Support: Loading and parsing Markdown from the local filesystem or remote sources (e.g., GitHub).
    • Frontmatter Parsing: Extracting metadata from Markdown files for use within Jaspr components.
    • Templating: Injecting data into content using templating languages like mustache.
    • Component Integration: Using built-in Jaspr components (like <Info> or <Tabs>) or custom ones to enhance content.
    • Layouts: Utilizing pre-defined layouts like DocsLayout or creating custom ones.
    • Theming: Leveraging a built-in theming system that supports light and dark modes out of the box.

    jaspr_content is fully compatible with standard Jaspr applications, allowing you to mix existing components and pages with content managed by jaspr_content.

  3. Overview of Jaspr

    main

    Jaspr is a modern fullstack web framework for building websites in Dart. It is designed to feel similar to Flutter but renders native HTML and CSS instead of using a canvas-based approach. This makes it suitable for building all types of websites (including SEO-sensitive content) that might not be ideal for Flutter Web.

    Key Capabilities:

    • Rendering Modes: Supports Client-Side Rendering (CSR), Server-Side Rendering (SSR), and Static Site Generation (SSG).
    • Component Model: Uses a component model similar to Flutter widgets.
    • State Syncing: Automatically synchronizes component state between the server and the client.
    • Performance: Performs direct DOM updates only where necessary for speed.
  4. What is Jaspr?

    main

    Jaspr is a modern fullstack web framework for building websites using the Dart programming language. It is designed to feel familiar to Flutter developers by using a component model similar to Flutter widgets, but instead of rendering to a canvas, it renders standard HTML and CSS.

    Key capabilities include:

    • Client-side and Server-side Rendering (SSR): Support for both rendering modes out of the box.
    • Automatic State Sync: Automatically synchronizes component state between the server and the client.
    • Optimized DOM Updates: Performs efficient updates to the DOM only where necessary.
    • Flexible Deployment: Can run on the server, the client, or both, with options for manual or automatic setup.
  5. Use Flutter embedding bindings in Jaspr

    main

    The jaspr_flutter_embed package provides bindings that allow you to embed Flutter components or logic within a Jaspr application. This enables developers to leverage the Flutter ecosystem while building web applications with Jaspr.

    For detailed implementation guides and advanced usage, refer to the official Jaspr documentation.

  6. Integrate Jaspr with Serverpod

    main

    The jaspr_serverpod package enables integration between Jaspr and Serverpod, providing tools for server-side rendering and connectivity.

    Key features include:

    • JasprRoute: Use this in your Serverpod webserver to server-side render Jaspr components.
    • context.session extension: Allows you to access the Serverpod Session directly inside a Jaspr component's build() method.
    • JasprConnectivityMonitor: A monitor designed for your generated Serverpod client.

    For detailed integration steps, refer to the official Setup Guide.

  7. Understand the dart_quotes_serverpod_client package

    main
    The dart_quotes_serverpod_client package serves as the client-side interface for interacting with your Serverpod backend. Most of the code within this package is automatically generated by Serverpod to match your server-side models and endpoints. While it is primarily generated code, you may manually modify it if you need to add custom modules or logic to your project.
  8. What is the Jaspr Precompiler?

    main

    The Jaspr Precompiler is a tool designed to precompile assets such as smart components and generate Dart source targets. These generated targets are used to support different rendering strategies, including:

    • SSG (Static Site Generation)
    • SSR (Server-Side Rendering)
    • CSR (Client-Side Rendering)

    The precompiler is scoped to compile only the source code within the current project.

  9. How sync overrides and scoping work

    main

    The lifecycle of a synced provider follows these steps:

    1. Server-side: The provider value is read, serialized, and embedded into the rendered HTML.
    2. Client-side: When the component containing ProviderScope first builds, the embedded value is read and deserialized.
    3. Override: The provider is then overridden on the client using Riverpod's .overrideWith() mechanism, skipping the initial computation.

    Important Note on Scoping: Overrides in Riverpod only propagate the provider chain when defined on the root ProviderScope. When using synced providers, ensure they are defined on the root client-side ProviderScope, or use the dependencies option to correctly scope them.

  10. Component categories in the Jaspr standard library

    main

    The standard library organizes components into functional categories. While the library is intended to grow, the primary categories include:

    • Layout: Components used for arranging and positioning other components.
    • Text: Components dedicated to displaying text content.
    • Forms & Input: Components for handling user input and interactive elements.
  11. Use State-Management packages in Jaspr

    main

    Because Jaspr's component system is conceptually and implementation-wise similar to Flutter's widget system, many popular Flutter state-management packages have been ported to Jaspr.

    An official port of flutter_riverpod is available as jaspr_riverpod.

    jaspr_riverpod
  12. Use a custom backend with Jaspr

    main

    By default, Jaspr uses the shelf package to create an HTTP server that handles requests and renders components. If you want to use a different Dart backend framework, you can replace the default server handling using two primary functions:

    1. Handler serveApp(AppHandler handler): Bundles Jaspr's server-side logic into a custom shelf handler. This handler can then be passed to your specific backend implementation.
    2. String renderComponent(Component app): Directly renders a provided component into an HTML string.

    Note on Auto-reload: When using a custom backend setup, running jaspr serve will still work, but automatic server-side reloading will not function. You will need to manage the server lifecycle manually.