humid 0.7.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +36 -45
- data/lib/humid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8a07ab8d934750bbdb01dc4596426d02edd7733d7bf87093b8ca36d5abbbb33
|
|
4
|
+
data.tar.gz: d3c9f28d92d637d8d4eb20e78676a0eacf09d7c922c0583448f3aacc1befe4fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 311cdf7125016802906bc28b7545c80c22e01709ebe679ead307f68783bab051a9e30bc634b777ce41802ad9d6564288305c593aee5da05a40e853b8a7ce31f2
|
|
7
|
+
data.tar.gz: 43777369d6c7b2525957d11117be0b1df56e960dbea0ca7be822ebb1b0d7c1e9af5f406fea47619d7f50829e203f610fb1074b1435b6ccce310453f1db04bf05
|
data/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./images/svg/humid-icon.svg" alt="Humid" width="128" />
|
|
3
|
+
<h1>Humid</h1>
|
|
4
|
+
<p>A few helpers for Javascript server-side rendering on Rails with <a
|
|
5
|
+
href="https://github.com/rubyjs/mini_racer">mini_racer</a></p>
|
|
6
|
+
</div>
|
|
2
7
|
|
|
3
8
|

|
|
4
9
|
|
|
@@ -12,16 +17,20 @@ returns an HTML string.
|
|
|
12
17
|
|
|
13
18
|
## Design
|
|
14
19
|
|
|
15
|
-
Humid is designed
|
|
16
|
-
rendering. Your application fetches everything needed, passes it as props, and
|
|
17
|
-
Humid returns the rendered HTML in a single synchronous call. It does not
|
|
18
|
-
support streaming or async data fetching during render.
|
|
20
|
+
Humid is designed with 2 goals in mind:
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
1. Its for the common case where all data is gathered before rendering. Your
|
|
23
|
+
application fetches everything needed, passes it as props, and Humid returns
|
|
24
|
+
the rendered HTML in a single synchronous call. It does not support streaming
|
|
25
|
+
or async data fetching during render.
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
2. Its a stepping stone for when you want to scale on the edge using
|
|
28
|
+
[Cloudflare V8 isolates](https://developers.cloudflare.com/workers/reference/how-workers-works/)
|
|
29
|
+
.`mini_racer` is a bare V8 environment, if your JS bundle works with
|
|
30
|
+
`mini_racer`, it'll work on Cloudflare V8 isolates.
|
|
31
|
+
|
|
32
|
+
> [!NOTE]
|
|
33
|
+
> See the [sample](./sample/) for a complete working example.
|
|
25
34
|
|
|
26
35
|
## Installation
|
|
27
36
|
|
|
@@ -72,7 +81,8 @@ Humid.configure do |config|
|
|
|
72
81
|
end
|
|
73
82
|
|
|
74
83
|
if Rails.env.local?
|
|
75
|
-
# Use single_threaded mode for
|
|
84
|
+
# Use single_threaded mode for dev and test environments.
|
|
85
|
+
# This will also work for mini_test parallel tests
|
|
76
86
|
MiniRacer::Platform.set_flags! :single_threaded
|
|
77
87
|
MINI_RACER_SSR = { context: MiniRacer::Context.new(timeout: 1000, ensure_gc_after_idle: 2000) }
|
|
78
88
|
|
|
@@ -161,9 +171,6 @@ MINI_RACER_SSR = { context: ctx }
|
|
|
161
171
|
> [!NOTE]
|
|
162
172
|
> If you pass a context that was already prepared, `prepare` will noop and return the context back to you.
|
|
163
173
|
|
|
164
|
-
See the [sample server_rendering.tsx](./sample/server_rendering.tsx) to see how
|
|
165
|
-
it is integrated.
|
|
166
|
-
|
|
167
174
|
### Call `Humid.render`
|
|
168
175
|
|
|
169
176
|
And finally call `render` from ERB.
|
|
@@ -221,17 +228,19 @@ The default formatter returns `message` unchanged.
|
|
|
221
228
|
|
|
222
229
|
## Server-side libraries that detect node.js envs.
|
|
223
230
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
Some libraries check for Node.js or browser globals to decide which code path
|
|
232
|
+
to use. In `mini_racer`, neither environment is detected. You may need to
|
|
233
|
+
configure your bundler to alias server-friendly versions. For example, in
|
|
234
|
+
esbuild:
|
|
235
|
+
|
|
236
|
+
```js
|
|
237
|
+
// build_ssr.mjs
|
|
238
|
+
await esbuild.build({
|
|
239
|
+
// ...
|
|
240
|
+
alias: {
|
|
241
|
+
'html-dom-parser': 'html-dom-parser/lib/html-to-dom-server'
|
|
233
242
|
}
|
|
234
|
-
|
|
243
|
+
})
|
|
235
244
|
```
|
|
236
245
|
|
|
237
246
|
## Writing universal code
|
|
@@ -263,28 +272,9 @@ moving the `require` to `useEffect` in your component.
|
|
|
263
272
|
## Polyfills
|
|
264
273
|
|
|
265
274
|
React SSR may import node.js dependencies that you need to polyfill for. See
|
|
266
|
-
a sample esbuild [build script](./sample/
|
|
275
|
+
a sample esbuild [build script](./sample/build.mjs) and a [shim.js](./sample/shim.js)
|
|
267
276
|
to get around these issues.
|
|
268
277
|
|
|
269
|
-
## Testing
|
|
270
|
-
|
|
271
|
-
The snippet When running in test environments that fork (e.g., parallel tests), each
|
|
272
|
-
worker needs its own context since MiniRacer is not fork-safe. Using
|
|
273
|
-
`MINI_RACER_SSR` as a hash makes this straightforward:
|
|
274
|
-
|
|
275
|
-
```ruby
|
|
276
|
-
ActiveSupport.on_load(:action_dispatch_integration_test) do
|
|
277
|
-
parallelize_setup do
|
|
278
|
-
MINI_RACER_SSR[:context].dispose
|
|
279
|
-
MINI_RACER_SSR[:context] = MiniRacer::Context.new(timeout: 1000, ensure_gc_after_idle: 2000)
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
parallelize_teardown do
|
|
283
|
-
MINI_RACER_SSR[:context].dispose
|
|
284
|
-
end
|
|
285
|
-
end
|
|
286
|
-
```
|
|
287
|
-
|
|
288
278
|
## Telemetry
|
|
289
279
|
|
|
290
280
|
The `MiniRacer::Context` gives you access to V8 heap statistics for monitoring
|
|
@@ -321,13 +311,14 @@ end
|
|
|
321
311
|
A steadily climbing `used_heap_size` across requests indicates a memory leak in
|
|
322
312
|
your JavaScript bundle.
|
|
323
313
|
|
|
314
|
+
|
|
324
315
|
## Contributing
|
|
325
316
|
|
|
326
317
|
Please see [CONTRIBUTING.md](/CONTRIBUTING.md).
|
|
327
318
|
|
|
328
319
|
## License
|
|
329
320
|
|
|
330
|
-
Humid is Copyright © 2021-
|
|
321
|
+
Humid is Copyright © 2021-2026 Johny Ho.
|
|
331
322
|
It is free software, and may be redistributed under the terms specified in the
|
|
332
323
|
[LICENSE](/LICENSE.md) file.
|
|
333
324
|
|
|
@@ -350,4 +341,4 @@ We are [available for hire][hire].
|
|
|
350
341
|
|
|
351
342
|
[mini_racer]: https://github.com/rubyjs/mini_racer
|
|
352
343
|
[vue_ssr]: https://ssr.vuejs.org/
|
|
353
|
-
[sample]: ./
|
|
344
|
+
[sample]: ./sample/
|
data/lib/humid/version.rb
CHANGED