1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//! React Container Component
//!
//! Provides a Dioxus component for mounting React applications using a
//! folder asset + manifest pattern. The build step generates `metadata.json`
//! describing the output files, and `ReactApp` reads it to load the correct
//! CSS/JS chunks — no manual renaming or copying needed.
//!
//! # Breaking Changes (0.2.0)
//!
//! - Removed `ReactContainer` (single bundle.js only)
//! - `ReactApp` now uses `dir` (folder asset) + `manifest` (ReactManifest) instead
//! of individual `bundle` / `stylesheet` asset props
//!
//! # Usage
//!
//! ```rust,ignore
//! const REACT_DIR: Asset = asset!("/assets/react");
//!
//! // Parse metadata.json at compile time
//! let manifest = ReactManifest::from_json(
//! include_str!("../assets/react/metadata.json")
//! ).expect("invalid metadata.json");
//!
//! rsx! {
//! ReactApp {
//! dir: REACT_DIR,
//! manifest: manifest,
//! bridge: bridge,
//! }
//! }
//! ```
use *;
use Deserialize;
/// Build manifest describing the React app's output files.
///
/// Generated by the build step as `metadata.json` in the dist folder.
/// Contains the hashed filenames so the Rust side can load them correctly.
///
/// # Example metadata.json
/// ```json
/// {
/// "scripts": ["chunk-2b2s0nqa.js"],
/// "styles": ["chunk-q7kzc8rh.css"],
/// "assets": ["logo-kygw735p.svg", "react-c5c0zhye.svg"]
/// }
/// ```
/// React application container — loads a React app from a folder asset + manifest.
///
/// Uses Dioxus's folder asset feature to reference the entire React build output
/// directory. The manifest describes which CSS/JS files to load (with their
/// hashed filenames), so no renaming or copying is needed.
///
/// The component:
/// 1. Loads all stylesheets listed in the manifest
/// 2. Injects the IPC bridge script (if provided)
/// 3. Creates the mount point `<div>` and loads all JS bundles
///
/// # Example
/// ```rust,ignore
/// use dioxus::prelude::*;
/// use dioxus_react_integration::prelude::*;
/// use std::time::Duration;
///
/// const REACT_DIR: Asset = asset!("/assets/react");
///
/// fn app() -> Element {
/// let bridge = IpcBridge::builder()
/// .timeout(Duration::from_secs(30))
/// .build();
///
/// let manifest = ReactManifest::from_json(
/// include_str!("../assets/react/metadata.json")
/// ).expect("invalid metadata.json");
///
/// rsx! {
/// ReactApp {
/// dir: REACT_DIR,
/// manifest: manifest,
/// bridge: bridge,
/// }
/// }
/// }
/// ```
]
mount_id: String,
)