dinou 4.0.3 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
 
8
+ ## [4.0.5]
9
+
10
+ ### Fixed
11
+
12
+ - Pass props to RootLayout in BuildStaticPages.
13
+
14
+ ## [4.0.4]
15
+
16
+ ### Fixed
17
+
18
+ - Use Server Functions as Actions in Forms.
19
+ - Webpack config ignore pattern.
20
+ - buildStaticPages: pass context to getProps.
21
+ - refresh: actually do refresh of the same page.
22
+
23
+ ### Added
24
+
25
+ - React Compiler to Webpack (dev, prod), Rollup (dev, prod), and esbuild (prod).
26
+
8
27
  ## [4.0.3]
9
28
 
10
29
  ### Fixed
package/README.md CHANGED
@@ -39,9 +39,10 @@ Support for React Server Components (RSC), Server-Side Rendering (SSR), Static G
39
39
  - [Hybrid Rendering Engine](#hybrid-rendering-engine)
40
40
  - [Incremental Static Regeneration (ISR)](#incremental-static-regeneration-isr)
41
41
  - [Client Components](#client-components)
42
- - [Server Functions (`"use server"`) & Smart Suspense](#server-functions-use-server--smart-suspense)
42
+ - [Server Functions (`"use server"`) & Enhanced Suspense](#server-functions-use-server--enhanced-suspense)
43
43
  - [Usage in Client Components (Reactive)](#usage-in-client-components-reactive)
44
44
  - [Usage in Server Components (Streaming)](#usage-in-server-components-streaming)
45
+ - [Server Actions (Form Mutations)](#server-actions-form-mutations)
45
46
  - [Advanced Patterns: The "Dinou Pattern"](#advanced-patterns-the-dinou-pattern)
46
47
  - [The Concept](#the-concept)
47
48
  - [Implementation](#implementation)
@@ -50,6 +51,9 @@ Support for React Server Components (RSC), Server-Side Rendering (SSR), Static G
50
51
  - [2. `getStaticPaths` (Static Generation)](#2-getstaticpaths-static-generation)
51
52
  - [3. `revalidate` (ISR)](#3-revalidate-isr)
52
53
  - [4. `dynamic` (Force SSR)](#4-dynamic-force-ssr)
54
+ - [⚡ React Compiler & Automatic Optimizations](#-react-compiler--automatic-optimizations)
55
+ - [Integration Strategy](#integration-strategy)
56
+ - [Code Example](#code-example)
53
57
  - [📚 API Reference](#-api-reference)
54
58
  - [1. Components (`dinou`)](#1-components-dinou)
55
59
  - [2. Hooks & Utilities (`dinou`)](#2-hooks--utilities-dinou)
@@ -414,7 +418,7 @@ export default function Counter() {
414
418
  }
415
419
  ```
416
420
 
417
- ## Server Functions (`"use server"`) & Smart Suspense
421
+ ## Server Functions (`"use server"`) & Enhanced Suspense
418
422
 
419
423
  Dinou supports **Server Functions**, allowing you to call server-side logic directly from your Client Components like a Remote Procedure Call (RPC). A unique feature of Dinou is that Server Functions can return **rendered Components** (both Server or Client Components), not just JSON data.
420
424
 
@@ -477,6 +481,63 @@ export default async function Page({ params: { id } }) {
477
481
  }
478
482
  ```
479
483
 
484
+ ### Server Actions (Form Mutations)
485
+
486
+ Server Functions can also be used as **Server Actions** by passing them to the `action` prop of a `<form>`. This allows you to handle form submissions and data mutations directly on the server without creating API endpoints manually.
487
+
488
+ 1. **Automatic FormData:** The function receives a `FormData` object containing the input values.
489
+ 2. **Progressive Enhancement:** Forms work even before JavaScript loads.
490
+ 3. **Redirects:** Use `getContext` to redirect after a successful mutation.
491
+
492
+ ```javascript
493
+ // src/actions/create-post.js
494
+ "use server";
495
+ import { getContext } from "dinou";
496
+ import { addPost } from "@/db/posts.js";
497
+
498
+ export async function createPost(formData) {
499
+ const context = getContext();
500
+ const title = formData.get("title");
501
+ const content = formData.get("content");
502
+
503
+ await addPost({ title, content });
504
+
505
+ context?.res?.redirect("/posts");
506
+ }
507
+ ```
508
+
509
+ #### Usage in Components
510
+
511
+ You can import the function and use it directly in your JSX. You can also use the `useFormStatus` hook (from React 19) to show loading states while the action is executing.
512
+
513
+ ```jsx
514
+ // src/new-post/page.jsx
515
+ "use client";
516
+ import { useFormStatus } from "react-dom";
517
+ import { createPost } from "@/actions/create-post";
518
+
519
+ function SubmitButton() {
520
+ const { pending } = useFormStatus();
521
+ return (
522
+ <button type="submit" disabled={pending}>
523
+ {pending ? "Saving..." : "Create Post"}
524
+ </button>
525
+ );
526
+ }
527
+
528
+ export default function Page() {
529
+ return (
530
+ <form action={createPost}>
531
+ {/* The 'name' attribute is required for FormData extraction */}
532
+ <input name="title" placeholder="Title" required />
533
+ <textarea name="content" placeholder="Content" required />
534
+
535
+ <SubmitButton />
536
+ </form>
537
+ );
538
+ }
539
+ ```
540
+
480
541
  ## Advanced Patterns: The "Dinou Pattern"
481
542
 
482
543
  Dinou introduces a powerful pattern for handling mutations and list updates without full page reloads. By combining **Server Functions**, **Global State** (e.g., `jotai-wrapper`), and **`react-enhanced-suspense`**, you can achieve granular reactivity.
@@ -805,6 +866,55 @@ export function dynamic() {
805
866
  }
806
867
  ```
807
868
 
869
+ ## ⚡ React Compiler & Automatic Optimizations
870
+
871
+ Dinou integrates the **React Compiler** (React 19+) out of the box. It analyzes your code and automatically applies fine-grained memoization to values and functions.
872
+
873
+ This means you can stop manually writing `useMemo`, `useCallback`, and `React.memo`. Just write clean, idiomatic JavaScript, and Dinou ensures maximum performance at build time.
874
+
875
+ ### Integration Strategy
876
+
877
+ Dinou uses a sophisticated hybrid strategy to balance **Developer Experience (DX)** with **Production Performance**:
878
+
879
+ | Bundler | Development | Production | Status |
880
+ | :---------- | :-----------------: | :--------: | :------------------------------------------------------------------------------------------------------------------------------- |
881
+ | **Webpack** | ✅ Enabled | ✅ Enabled | Full optimization. |
882
+ | **Rollup** | ✅ Enabled | ✅ Enabled | Full optimization. |
883
+ | **Esbuild** | ⚡ **Native Speed** | ✅ Enabled | **Hybrid Mode:** Dev prioritizes instant HMR (Hot Module Replacement), while Prod injects the compiler for maximum optimization. |
884
+
885
+ ### Code Example
886
+
887
+ **The Old Way (Manual Optimization):**
888
+
889
+ ```jsx
890
+ function ExpensiveComponent({ data }) {
891
+ // Manual dependency management required
892
+ const processed = useMemo(() => heavyMath(data), [data]);
893
+
894
+ const handleClick = useCallback(() => {
895
+ console.log(processed);
896
+ }, [processed]);
897
+
898
+ return <Child onAction={handleClick} />;
899
+ }
900
+ ```
901
+
902
+ **The Dinou Way:**
903
+
904
+ ```jsx
905
+ function ExpensiveComponent({ data }) {
906
+ // ✨ Automatically memoized by Dinou
907
+ const processed = heavyMath(data);
908
+
909
+ // ✨ Automatically stable reference
910
+ const handleClick = () => {
911
+ console.log(processed);
912
+ };
913
+
914
+ return <Child onAction={handleClick} />;
915
+ }
916
+ ```
917
+
808
918
  ## 📚 API Reference
809
919
 
810
920
  ### 1. Components (`dinou`)