svelte-on-rails 0.0.44 → 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +87 -66
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e29d2736242589c4733b2fff2bd590cce4eff354ae529d049fe4a18f05c464a6
4
- data.tar.gz: 79fa789cd334dc3fdd248a53156d4845fe893b089147dd91a559b0618654fb12
3
+ metadata.gz: af9b4125161ea52c5785989db9e7f4b250a4bbe993f49264403680c5aa5467fb
4
+ data.tar.gz: 1d21a733aa52d57f892159baeb88c162cb78f46fca648dd2f31b45e3db8819e0
5
5
  SHA512:
6
- metadata.gz: e4cac68c628036a6bf53cae04e76523a1ee6ee91d645634b00097b3df8cd1b32c4b6b4d72fa8ede06542101922d9977a6546c86862ac013c97bc6625cb256e35
7
- data.tar.gz: 20667b507cbdb4dba14e9a00b74ce780ba05bd169e888d73b0d292cb997294e6665050b9a76e248efd1a477cb4e83cb46783a04193bc5e15d4102a0e454a4cfb
6
+ metadata.gz: 72c0797453be3020409b6e28f5b7f472e8e0c1a22e010c401925ad2a81ac360c522612a7e52bac3d7a8da5a4c51f62668a68d46a33b3a955ed9e072366a567fd
7
+ data.tar.gz: 7f377d2c359daa8a9a2e18cd7c147187dd4249bbd0a8b5987f0feddb4a7b72020bc49591e04502055e4a7223e78e05b8e832c21c345dc93ac1d943440587dfc0
data/README.md CHANGED
@@ -3,18 +3,22 @@
3
3
  Seamless and robust Svelte in Rails integration.
4
4
 
5
5
  By default, and when installed together with `@hotwired/turbo-rails`, it renders
6
- svelte components on first request server side («SSR») and for subsequent
7
- requests it provides a empty tag that will be mounted on the frontend by the associated npm package [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails) on the frontend.
6
+ svelte components on the first request server side («SSR») and for subsequent
7
+ requests it provides a empty tag which is mounted on the frontend
8
+ by the associated npm package [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails).
8
9
 
9
10
  This way svelte works perfectly together with turbo. You will never notice
10
- this unpleasant «blink» on the frontend and it is maximum performance
11
- optimized. SSR compilation is handled by vite.
11
+ this unpleasant «blink» on the frontend and is optimised for maximum
12
+ performance. SSR compilation is done by vite.
12
13
 
13
-
14
- This all is developed on Rails-7 together with `vite_rails`.
14
+ All this is developed on Rails-7 together with `vite_rails`.
15
15
 
16
16
  Thanks to [shakacode](https://github.com/shakacode/react_on_rails)
17
- and [ElMassimo](https://github.com/ElMassimo) because they all helped me with theyr gems.
17
+ and [ElMassimo](https://github.com/ElMassimo) for inspiring and helping me with their gems.
18
+
19
+ **STATUS** This gem is in early development but ready to use for curious developers.
20
+ It has a 100% test coverage, all tests pass.
21
+ It is not yet implemented on my customer projects, but this will follow soon.
18
22
 
19
23
  If you have issues, please open one and contributors are welcome!
20
24
 
@@ -30,9 +34,7 @@ If you have issues, please open one and contributors are welcome!
30
34
 
31
35
  ## Installation from cero
32
36
 
33
- together with haml, vite, svelte and turbo
34
-
35
- If you want to start from a new rails app, follow theese tutorials
37
+ With haml, vite, svelte and turbo:
36
38
 
37
39
  ```bash
38
40
  rails new my-test-app --skip-javascript
@@ -71,14 +73,17 @@ And there is the option `--force` that would not ask you whether it should overw
71
73
  This means, if you want all, except haml, you can run:
72
74
 
73
75
  ```bash
74
- rails g svelte_on_rails:install --vite --turbo --svelte --hello-world --force
76
+ rails g svelte_on_rails:install --vite --turbo --svelte --hello-world
75
77
  ```
76
78
 
77
- The installer is written carefully: It does not overwrite a file without asking.
78
- It tells you all what he is doing.
79
+ The installer is written carefully: It does not overwrite a file without asking
80
+ and tells you all what he is doing.
79
81
 
80
82
  At the end, you just have to (re-) start your server
81
- and you will see a Svelte component.
83
+ and you will see a Svelte Hello World component.
84
+
85
+ This hello world has a second page where the most common import statements are demonstrated,
86
+ separated for server and client side rendering.
82
87
 
83
88
  Then, you can run
84
89
 
@@ -111,34 +116,27 @@ Within the config file, there are mainly two important tags:
111
116
 
112
117
  ## Check if it all works
113
118
 
114
- Add a controller and a view with the helper `= svelte_component('HelloWorld', items: ['item1', 'item2'])`.
115
- On loading you will see
116
-
117
- - Rendered HelloWorld.svelte server-side: 0.075ms
119
+ Server Side Rendering (SSR) is a parallel pipeline to client side rendering.
120
+ Both should return the same html. And your global styles should be applied same way
121
+ for both cases. For 95% of use cases this is the case.
118
122
 
119
- On the rails console and you will see «Greetings from svelte»
120
- on your view with a styled «Increment» button.
121
- Styles you find within the svelte component.
122
- Click this button and see that the component is alive.
123
+ For check the **ssr pipeline** you can pass the options `ssr: true` and `hydrate: false`
124
+ to the view helper. This way you will see a «dead» html (no javascript is working).
123
125
 
124
- On [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails)
125
- are details how the frontend part is working.
126
+ For check the **client side pipeline** you can pass the option `ssr: false` and
127
+ `hydrate: true` to the view helper.
126
128
 
127
- Without the npm package installed,
128
- or by passing `ssr: true` and `hydrate: false` to the view helper,
129
- you would see the same html, and the styled button,
130
- but the increment button would not work.
131
-
132
- I inserted very detailed error messages on rails and on the
133
- npm package, for making sure that thisk setup is working.
134
- So please check the logs on your browser.
129
+ If both are looking similar, you are good to go. Then, remove theese options, the defaults are
130
+ `ssr: :auto` and `hydrate: true`.
135
131
 
136
132
  ### Import statements
137
133
 
138
- For check which statements are working and actively tested, please check the
139
- [components folder](https://gitlab.com/sedl/svelte-on-rails/-/tree/main/spec/rails-vite-test-app/app/frontend/javascript/components?ref_type=heads) within the gem specs.
134
+ The most importand import statements that are served by this gem are included in the
135
+ hello world component and by that they are also within the testing scope. So you can
136
+ be sure that they are working. If importand statements are missing there, pelase
137
+ tell me.
140
138
 
141
- Among others there are
139
+ Among others, working statements are:
142
140
 
143
141
  - `import svg from '../example.svg?raw'`
144
142
  - `<script lang="ts">` (svelte component with typescript syntax)
@@ -149,7 +147,7 @@ Among others there are
149
147
 
150
148
  Usual vite has a `vite.config.ts` file, that is used for the client side precompilation.
151
149
 
152
- By running this installer it adds a npm runner so that you can do `npm run build:ssr`
150
+ By running this installer it adds `vite-ssr.config.ts` and a npm runner so that you can do `npm run build:ssr`
153
151
  which does the server side precompilation.
154
152
 
155
153
  The same job is triggered alongside `rails assets:precompile` for production environments.
@@ -179,33 +177,6 @@ loaded on very first load to the frontend, then the most work is done
179
177
  in frontend and the server is relieved, except on initial request.
180
178
  You will see no unpleasant «blink» on the page.
181
179
 
182
- ## Styles
183
-
184
- For 99% of use cases you can just skip this chapter.
185
-
186
- You can simply work with global styles as well as styles within the svelte component.
187
-
188
- A server-side rendered svelte component has 2 states:
189
-
190
- #### Before hydration
191
-
192
- - The `svelte_component` view helper renders the styles contained within the component
193
- into a style tag within the component's wrapper element. This has to be done this way because of Turbo.
194
- - In very, very rare cases, global styles are not applied in the same way as after hydration.
195
-
196
- #### After hydration
197
-
198
- - Svelte adds a style tag inside the header
199
- - Svelte renders the component again, which removes the style tag inside the component wrapper.
200
-
201
- #### If you notice a "blink"
202
-
203
- For the app to look stable, both states must appear in the same way.
204
- Normally this is the case. But if there are problems,
205
- or you want to see the state before hydration, for development purposes, you can pass
206
- the `hydrate: false` option to the view helper,
207
- and no hydration will happen for this component.
208
-
209
180
  ## More rake tasks
210
181
 
211
182
  This tasks are more for testing/playground purposes
@@ -222,19 +193,28 @@ rails svelte_on_rails:remove_hello_world
222
193
 
223
194
  Contributors welcome!
224
195
 
225
- After downloaded the gem, please run the task
196
+ **Download the code and run the tests**
197
+
198
+ Download the source code from the repository, and within the project folder run:
226
199
 
227
200
  ```bash
228
201
  rake svelte_on_rails:create_contributor_configs_file
229
202
  ```
230
203
  and define a `generated_test_app_folder_path` (required) for apps, generated for the testings.
231
204
 
232
- For development of the **npm package @csedl/svelte-on-rails** you can set the
233
- `local_npm_package_path` (optional) and insert the path to the npm package on your local machine.
205
+ For development of the **npm package @csedl/svelte-on-rails** (optional) please download the source code of the
206
+ npm package and set
207
+ `local_npm_package_path` and set the path to the npm package on your local machine.
234
208
  This will cause the installer, to install the npm package from a local path instead from the npm registry.
235
209
 
210
+ Then run the tests and start contributing.
211
+
236
212
  Tests are based on the included templates, like the `hello world template` and on the installer.
237
213
 
214
+ Here I learned how to write tests! Testing installers is heavy, you will read about it in the
215
+ test_helpers. But I have done my best to give all the code a clear structure.
216
+ I hope you like it, and improvements are welcome.
217
+
238
218
  **Installer tests** starting with completely destroy the rails app within the `generated_test_app_path`,
239
219
  generating a new rails app and running the installer and test by `playwright` if the components are working.
240
220
 
@@ -260,6 +240,47 @@ The current test cases including (among others):
260
240
  create a completely new rails app, running the full installer and check if a hello World component is visible and javascript is working.
261
241
  run assets:precompile within a rails app and check if the gem does its precompiling too.
262
242
 
243
+ ## Understanding the process
244
+
245
+ **Why not client and server rendering in one process?**
246
+
247
+ That was my idea! `application.js` which is the usual entry point for the client
248
+ side could live on the same assets and manifest like svelte components that are
249
+ compiled as chunks which each is its own entry point. This failed:
250
+
251
+ - The `vite-plugin-ruby` did not support this: it constrained all to one entry point.
252
+ - See how fat the `vite-ssr.config.ts`. For the client side this is not necessary.
253
+
254
+ At the end, I decided to split the process. But that is not the last decision.
255
+
256
+ **Why not compiling server side purely by rollup?**
257
+
258
+ Advantages would be much slimmer packages and faster compilation. On the first
259
+ step i did this and i backed up a working and tested code on the branch [rollup-ssr](https://gitlab.com/sedl/svelte-on-rails/-/blob/rollup-ssr/BRANCH_INFO.md?ref_type=heads).
260
+
261
+ I decided to use Vite to bring the client and server side rendering
262
+ closer together.
263
+
264
+ But this, too, is not the last decision.
265
+
266
+ For now we proceed with vite.
267
+
268
+ **How does it work now?**
269
+
270
+ Client side rendering is done by vite like usual.
271
+
272
+ Server side rendering is triggered, similar to [vite_rails](https://vite-ruby.netlify.app/guide/deployment.html)
273
+ on `assets:precompile`, and, if `watch_changes` is configured,
274
+ which is default for development, it is triggered
275
+ on every change of a `*.svelte` file within the configured `components_folder`.
276
+
277
+ On the server side only the `*.svelte` files are served. Theyr included
278
+ assets are linked to the client side assets folder, which is mapped by `manifest.json`.
279
+
280
+ Then, vite has two output folders: `vite-dev` for development and `vite` for production.
281
+ Within `vite-ssr.config.ts`, by the `RAILS_ENV` variable, is decided which one is used.
282
+
283
+
263
284
  ## Licence
264
285
 
265
286
  License is MIT
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair