Commit f7d948d
authored
Add cached_stream_react_component helper (#549)
Follow-up to #548
### What
- Introduces `cached_stream_react_component`, mirroring
`cached_react_component`:
- Requires `cache_key` and `props` block (lazy props on HIT)
- Honors `:if` / `:unless` and `:cache_options` (TTL/compression)
- Implements view-level streaming cache by decorating the fiber produced
by `stream_react_component`:
- **MISS**: call `stream_react_component` once, wrap its fiber to buffer
chunks and write-through to `Rails.cache`; return initial chunk
immediately
- **HIT**: read cached chunks; return initial chunk and push a replay
fiber for the remainder
- Preserves streaming semantics/formatting; no behavior change unless
the helper is used
- Adds/updates helper spec coverage to exercise MISS→HIT, skip,
invalidation, and TTL
### Why
- Prerender caching keys by `js_code` digest (needs serialized props),
so it can’t lazily skip props
- View-level cache enables app-defined keys and true lazy props
evaluation on HIT, matching the non-stream helper’s ergonomics
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Adds cached streaming for server-rendered React components to speed
repeat requests while preserving prerender/hydration behavior, honoring
existing cache controls, conditional caching, and instrumentation.
* Adds a demo/test page and route for the cached streaming variant.
* **Tests**
* Expanded unit and system tests covering cache miss→hit flow,
write-through caching, invalidation on prop changes,
skip-prerender-cache, that props are not re-evaluated on hit, streaming
chunk ordering, and deterministic mocked streaming.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 4e51b46 commit f7d948d
File tree
5 files changed
+329
-7
lines changed- app/helpers
- spec/dummy
- app
- controllers
- views/pages
- config
- spec/helpers
5 files changed
+329
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
94 | 113 | | |
95 | 114 | | |
96 | 115 | | |
97 | 116 | | |
| 117 | + | |
98 | 118 | | |
99 | 119 | | |
100 | 120 | | |
101 | 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 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
102 | 187 | | |
103 | 188 | | |
104 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
0 commit comments