Skip to content

Commit f2a545f

Browse files
committed
Add option to disable ssr globally in config
1 parent 0bcbbe0 commit f2a545f

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,21 @@ In theses cases you can turn off SSR.
472472

473473
#### Disabling SSR
474474

475-
SSR is enabled by default when you install LiveSvelte. If you don't want to use Server-Side Rendering for Svelte, you have 2 options:
475+
SSR is enabled by default when you install LiveSvelte. If you don't want to use Server-Side Rendering for Svelte, you can disable it in the following ways:
476476

477477
##### Globally
478478

479479
If you don't want to use SSR on any component you can disable it globally.
480-
This will automatically be the case if you don't include the `NodeJS` supervisor in the `application.ex` file
480+
481+
There are 2 ways of doing this
482+
- Don't include the `NodeJS` supervisor in the `application.ex` file
483+
or
484+
- Add `ssr: false` to the `live_svelte` config in your `config.exs` file like so:
485+
486+
```elixir
487+
config :live_svelte,
488+
ssr: false
489+
```
481490

482491
##### Component
483492

config/config.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Config
22

33
config :live_svelte,
4-
ssr_module: LiveSvelte.SSR.NodeJS
4+
ssr_module: LiveSvelte.SSR.NodeJS,
5+
ssr: true
56

67
if Mix.env() == :dev do
78
esbuild = fn args ->

example_project/config/config.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ config :logger, :console,
4949
# Use Jason for JSON parsing in Phoenix
5050
config :phoenix, :json_library, Jason
5151

52+
# Configure live_svelte
53+
config :live_svelte,
54+
ssr: true
55+
5256
# Import environment specific config. This must remain at the bottom
5357
# of this file so it overrides the configuration defined above.
5458
import_config "#{config_env()}.exs"

lib/component.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ defmodule LiveSvelte do
6464
def svelte(assigns) do
6565
init = assigns.__changed__ == nil
6666
dead = assigns.socket == nil or not LiveView.connected?(assigns.socket)
67+
ssr_active = Application.get_env(:live_svelte, :ssr, true)
6768

6869
slots =
6970
assigns
7071
|> Slots.rendered_slot_map()
7172
|> Slots.js_process()
7273

7374
ssr_code =
74-
if init and dead and assigns.ssr do
75+
if init and dead and ssr_active and assigns.ssr do
7576
try do
7677
props =
7778
Map.merge(

0 commit comments

Comments
 (0)