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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8a07ab8d934750bbdb01dc4596426d02edd7733d7bf87093b8ca36d5abbbb33
4
- data.tar.gz: d3c9f28d92d637d8d4eb20e78676a0eacf09d7c922c0583448f3aacc1befe4fa
3
+ metadata.gz: 4dace2fdf5d12412e01d86b520b5d77fd3fd04dd207b2815d93d0473283fa6a8
4
+ data.tar.gz: d8c40b486faa9f905c04c3d31c4eabd0cd304d0ad98d1666b1d76ad2aae32e0c
5
5
  SHA512:
6
- metadata.gz: 311cdf7125016802906bc28b7545c80c22e01709ebe679ead307f68783bab051a9e30bc634b777ce41802ad9d6564288305c593aee5da05a40e853b8a7ce31f2
7
- data.tar.gz: 43777369d6c7b2525957d11117be0b1df56e960dbea0ca7be822ebb1b0d7c1e9af5f406fea47619d7f50829e203f610fb1074b1435b6ccce310453f1db04bf05
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
- ## Polyfills
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
- React SSR may import node.js dependencies that you need to polyfill for. See
275
- a sample esbuild [build script](./sample/build.mjs) and a [shim.js](./sample/shim.js)
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
@@ -1,3 +1,3 @@
1
1
  module Humid
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho