humid 1.0.0 → 1.1.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 +44 -4
- data/lib/humid/version.rb +1 -1
- data/lib/humid.rb +5 -0
- 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: 4dace2fdf5d12412e01d86b520b5d77fd3fd04dd207b2815d93d0473283fa6a8
|
|
4
|
+
data.tar.gz: d8c40b486faa9f905c04c3d31c4eabd0cd304d0ad98d1666b1d76ad2aae32e0c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: afc89db87f4b324b01b08a1f907ae74fd88a420b8c275095b9e7e44b8cf21e711b31dc18dbc0b021d85d8debca4e50986be1a16a2b43eec2a27ad1de6cc668c2
|
|
7
|
+
data.tar.gz: 1564ce03048d337b38891607afbbc360e47e5898601cb78a984ce4a003aafe1b3ff95dc6dc0a3faa70a6b6703446b11d7ddb86185250ad68e36e65401bf3dcb8
|
data/README.md
CHANGED
|
@@ -78,6 +78,13 @@ Humid.configure do |config|
|
|
|
78
78
|
#
|
|
79
79
|
# Defaults to `nil`
|
|
80
80
|
config.logger = Rails.env.local? ? Rails.logger : nil
|
|
81
|
+
|
|
82
|
+
# Path to a JavaScript file to eval into the MiniRacer context
|
|
83
|
+
# before the application bundle. Use this to provide globals that
|
|
84
|
+
# bare V8 doesn't have (TextEncoder, URL, MessageChannel, etc.).
|
|
85
|
+
#
|
|
86
|
+
# Optional. Defaults to nil (no prepend).
|
|
87
|
+
# config.prepend = Rails.root.join("path/to/shim.js")
|
|
81
88
|
end
|
|
82
89
|
|
|
83
90
|
if Rails.env.local?
|
|
@@ -269,11 +276,44 @@ moving the `require` to `useEffect` in your component.
|
|
|
269
276
|
}, [])
|
|
270
277
|
```
|
|
271
278
|
|
|
272
|
-
##
|
|
279
|
+
## MiniRacer Shim
|
|
280
|
+
|
|
281
|
+
MiniRacer runs bare V8 — no browser APIs, no Node APIs. React SSR and
|
|
282
|
+
libraries like `whatwg-url` expect globals that don't exist. Humid ships
|
|
283
|
+
a pre-built shim in [`shim/dist/shim.js`](./shim/) that provides:
|
|
284
|
+
|
|
285
|
+
- **TextEncoder / TextDecoder** — real implementation from `text-encoding`
|
|
286
|
+
(not stubs — `whatwg-url` needs them to actually encode strings)
|
|
287
|
+
- **URL / URLSearchParams** — from `whatwg-url`
|
|
288
|
+
- **MessageChannel** — stub (React's scheduler references it)
|
|
289
|
+
- **navigator** — stub with `language: 'en-us'`
|
|
290
|
+
- **source-map-support** — rewrites JS stack traces using source maps,
|
|
291
|
+
so Humid errors show original filenames and line numbers
|
|
292
|
+
(`app/views/posts/show.html.tsx:42`) instead of bundled positions
|
|
293
|
+
(`server_rendering.js:12345`)
|
|
294
|
+
|
|
295
|
+
Use it with the `prepend` config option:
|
|
296
|
+
|
|
297
|
+
```ruby
|
|
298
|
+
Humid.configure do |config|
|
|
299
|
+
config.prepend = Rails.root.join("path/to/shim.js")
|
|
300
|
+
end
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The shim is eval'd into the MiniRacer context before your SSR bundle,
|
|
304
|
+
so all globals are available when your code initializes.
|
|
305
|
+
|
|
306
|
+
To rebuild the shim (e.g., after updating dependencies):
|
|
307
|
+
|
|
308
|
+
```sh
|
|
309
|
+
cd shim
|
|
310
|
+
npm install
|
|
311
|
+
npm run build
|
|
312
|
+
# outputs shim/dist/shim.js
|
|
313
|
+
```
|
|
273
314
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
to get around these issues.
|
|
315
|
+
See the [shim README](./shim/README.md) for details on the two-stage
|
|
316
|
+
build process.
|
|
277
317
|
|
|
278
318
|
## Telemetry
|
|
279
319
|
|
data/lib/humid/version.rb
CHANGED
data/lib/humid.rb
CHANGED
|
@@ -44,6 +44,11 @@ module Humid
|
|
|
44
44
|
ctx.attach("console.warn", proc { |*args| logger.warn(fmt.call(:warn, *args)) })
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
prepend_path = effective_config.prepend
|
|
48
|
+
if prepend_path
|
|
49
|
+
ctx.eval(File.read(prepend_path))
|
|
50
|
+
end
|
|
51
|
+
|
|
47
52
|
js = remove_functions + renderer
|
|
48
53
|
ctx.eval(js)
|
|
49
54
|
|