vite_react 0.1.9 → 0.1.10

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: 2f28f90a9c6f9c9dfd5efdb6e1e288e78a5f9305880db251fc21706b5742eee2
4
- data.tar.gz: b91bac8c6584a27aae375f4ae49b1abb6732e1f15b1ba56a90aa80c153f6d1d5
3
+ metadata.gz: 4eac2bfb320db0bea766f7e2cc7106272735504e6af56e0534c98385733d4c28
4
+ data.tar.gz: a698fc6cd218784592fd9bafc544617b7d0b8af8e2a6d15bd78633bb9a62f16c
5
5
  SHA512:
6
- metadata.gz: 93f1c399a4fcbd39a748cc4808a1a946f2287b3072aea62bea11f325f7676831aa2cf53a5e934bb718a068cfe0004ea4d619df617d1dfd50b06b0fa1bac15a82
7
- data.tar.gz: 6b6d4bafd733f87c8ca3af776299f47f462d36b43f9e47d9c65f0e9e614ded38bbe17bf2e48b495b5143b76b1a1282e249239afd6e7179c81ca503f1fe458c84
6
+ metadata.gz: 75f2bbf8ae2c246aa97f8b0987672d2fd31a98033262335725482fa46d103b7278e40dfb317a587881641d066ac9b185d2c607e8f4a5d35d6ffd5b8b81d0c744
7
+ data.tar.gz: 90582d6240609c4696cb78a96b820fcfdcdd068273635b1907df15ce1dffc261372e3f92c1d6cd0a0e54b14cb715c41a0cb93431d492b023c4b8ac46edf7f63d
data/lib/install/ssr.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import express, { Request, Response } from 'express';
2
2
  import { createServer as createViteServer } from 'vite';
3
3
  import React from "react";
4
+
4
5
  import { renderToPipeableStream } from "react-dom/server";
5
6
  import parse from 'html-react-parser';
6
7
 
@@ -11,18 +12,15 @@ const port = process.env.PORT || 4000;
11
12
  async function startServer() {
12
13
  const app = express();
13
14
 
14
- // Create Vite server in middleware mode.
15
15
  const vite = await createViteServer({
16
16
  server: { middlewareMode: true },
17
17
  appType: 'custom'
18
18
  });
19
19
 
20
- // Use Vite's middleware.
21
20
  app.use(vite.middlewares);
22
21
 
23
22
  app.use(express.json());
24
23
 
25
- // SSR render endpoint
26
24
  app.post("/render", async (req: Request, res: Response) => {
27
25
  try {
28
26
  const { component, props } = req.body;
@@ -7,21 +7,10 @@ else
7
7
  exit
8
8
  end
9
9
 
10
- gem "vite_rails"
10
+ gem "vite_rails", "~> 3.0"
11
11
  # gem "turbo-mount", "~> 0.4.1"
12
- gem "tailwindcss-ruby"
13
- gem "tailwindcss-rails"
14
- gem "opentelemetry-sdk"
15
- gem "opentelemetry-instrumentation-rails"
16
- gem "opentelemetry-exporter-otlp"
17
- gem "yabeda"
18
- gem "yabeda-gc"
19
- gem "yabeda-rails"
20
- gem "yabeda-activerecord"
21
- gem "yabeda-activejob"
22
- gem "yabeda-prometheus"
23
-
24
-
12
+ gem "tailwindcss-ruby", "~> 4.0.0"
13
+ gem "tailwindcss-rails", "~> 4.0"
25
14
 
26
15
  rails_command "tailwindcss:install"
27
16
 
@@ -37,7 +26,6 @@ say "=== Installing Vite, React, Tailwind, shadcn, etc. ===", :green
37
26
  # --- Vite ---
38
27
  run "bundle exec vite install"
39
28
 
40
-
41
29
  # --- Install NPM dependencies ---
42
30
  run <<~CMD
43
31
  npm install \
@@ -129,24 +117,13 @@ copy_file "#{__dir__}/tailwind.config.js", "tailwind.config.js"
129
117
  remove_file "Procfile.dev"
130
118
  copy_file "#{__dir__}/Procfile.dev", "Procfile.dev"
131
119
 
132
-
133
- # --------------------------------------------------------------------------
134
- # 2.8 setup telemetry
135
- # --------------------------------------------------------------------------
136
- template "#{__dir__}/opentelemetry.rb.tt", "config/initializers/opentelemetry.rb"
137
- insert_into_file "config/routes.rb",
138
- before: " get \"up\" => \"rails/health#show\", as: :rails_health_check\n" do
139
- " mount Yabeda::Prometheus::Exporter, at: \"/metrics\"\n"
140
- end
141
-
142
120
  gsub_file "app/views/layouts/application.html.erb",
143
121
  /<%= vite_javascript_tag 'application' %>/,
144
122
  "<%= vite_javascript_tag 'application.jsx' %>"
145
123
  rails_command "assets:precompile"
146
124
  run "bundle exec vite build --ssr"
147
- # --------------------------------------------------------------------------
148
- # 2.9: Done!
149
- # --------------------------------------------------------------------------
125
+
126
+
150
127
  say "=== Setup Complete ===", :green
151
128
  say "You can now run: bin/rails server", :yellow
152
129
  say "Visit http://localhost:3000 to see the example turbo-mounted React component.", :yellow
@@ -106,25 +106,35 @@ module ViteReact
106
106
 
107
107
  private
108
108
 
109
- def render_react_component_ssr(name, props, filename = nil)
110
- port = 4000 # Alternatively, use ViteReact.config.node_server_port || 4000
111
- uri = URI("http://localhost:#{port}/render")
112
- http = Net::HTTP.new(uri.host, uri.port)
113
- req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
114
- payload = { component: name, props: props }
115
- payload[:filename] = filename if filename
116
- req.body = payload.to_json
117
109
 
118
- res = http.request(req)
119
- if res.is_a?(Net::HTTPSuccess)
120
- res.body.html_safe
121
- else
122
- Rails.logger.error("SSR Error: #{res.code} #{res.body}")
123
- "Error rendering component"
124
- end
110
+
111
+ def render_react_component_ssr(name, props, filename = nil)
112
+ port = 4000
113
+ uri = URI("http://localhost:#{port}/render")
114
+ http = Net::HTTP.new(uri.host, uri.port)
115
+ req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json; charset=utf-8")
116
+
117
+ payload = { component: name, props: props }
118
+ payload[:filename] = filename if filename
119
+ req.body = payload.to_json
120
+
121
+ res = http.request(req)
122
+
123
+ if res.is_a?(Net::HTTPSuccess)
124
+ expected_encoding = Encoding.default_internal || Encoding.default_external
125
+
126
+ body = res.body
127
+ body = body.force_encoding(expected_encoding) unless body.encoding == expected_encoding
128
+
129
+ body.html_safe
130
+ else
131
+ Rails.logger.error("SSR Error: #{res.code} #{res.body}")
132
+ "Error rendering component"
133
+ end
125
134
  rescue => e
126
135
  Rails.logger.error("SSR Exception: #{e.message}")
127
136
  "Error rendering component"
128
137
  end
129
138
  end
130
139
  end
140
+
@@ -1,3 +1,3 @@
1
1
  module ViteReact
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vite_react
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - lsproule
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-08 00:00:00.000000000 Z
10
+ date: 2025-10-12 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -128,7 +128,6 @@ files:
128
128
  - lib/install/application.jsx
129
129
  - lib/install/components.json
130
130
  - lib/install/index.html.erb
131
- - lib/install/opentelemetry.rb.tt
132
131
  - lib/install/postcss.config.mjs
133
132
  - lib/install/ssr.ts
134
133
  - lib/install/tailwind.config.js
@@ -1,10 +0,0 @@
1
- require "opentelemetry/sdk"
2
- require "opentelemetry/instrumentation/rails"
3
- require "opentelemetry-exporter-otlp"
4
-
5
-
6
- OpenTelemetry::SDK.configure do |c|
7
- c.service_name = "<%= Rails.application.class.module_parent_name.underscore.dasherize %>"
8
- c.use_all()
9
- end if Rails.env.production?
10
-