polypush135

polypush135

Thinking about writing a custom adapter for Svelte serverside rendering (SSR) via Phoenix HTML Views

So I’ve been digging into svelte the last few days and I have to say I’m really hooked.

I’m not going to spend this time telling you why you should given it an honest try.

That said its still lacking something that I feel will just put it over the top as being my favorite stack.

I’m envisioning what a custom Svelte adapter would look like for doing SSR with svelte but via Phoenix Heex. I know there is already GitHub - woutdp/live_svelte: Svelte inside Phoenix LiveView with seamless end-to-end reactivity · GitHub

But I want to go more abstract than that and not use really any fronted on Phoenix (ie no liveview) and just use Phoenix as a way to possible aid in doing SSR for svenlte like looking up records as a part of the initial request and inital html payload.

At the moment this is just a nebulas idea and I am looking for any input.
Thoughts? Considerations?

FYI: I’m starting with this as my first steps. Writing adapters • SvelteKit Docs

Some initial thoughts:

  1. Request Handling: A web request is received by the Phoenix server. Phoenix’s routing determines the correct controller and action to handle the request.

  2. Invoking JavaScript Runtime: Within the controller action, the Phoenix server needs to interact with a JavaScript runtime to render the Svelte components. This can be achieved through:

    • External Node.js process: Phoenix can make a call to a Node.js process that handles the rendering of Svelte components.
    • Embedded JavaScript interpreter: Using tools like ExecJS in Ruby, though an Elixir equivalent would be needed.
  3. Rendering Svelte Components: The JavaScript runtime receives the data and renders the Svelte components server-side. This step involves:

    • Converting Elixir data structures to a format understandable by JavaScript.
    • Running the Svelte compiler to generate HTML and CSS.
  4. Returning Rendered Content: The rendered HTML and CSS from Svelte are returned to the Phoenix server.

  5. Phoenix View Integration:

    • The returned HTML can be integrated into Phoenix templates (eex or leex). Phoenix Views can then be used to inject this HTML into the overall page template.
    • Alternatively, the Phoenix response can be constructed to directly send back the rendered HTML and CSS, bypassing traditional templates.
  6. Sending Response to Client: Finally, the Phoenix server sends the response back to the client, which includes the server-rendered HTML of the Svelte components.

Where Next?

Popular in Discussions Top

WildYorkies
It seems that the more I read, the more I find Elixir users speaking about all the ways that Elixir is not good for x, y, and z use cases...
New
blackode
Elixir Upgrading is so Simple in Ubuntu and It worked for me Ubuntu 16.04 git clone https://github.com/elixir-lang/elixir.git cd elixir...
New
laiboonh
Hi all, I am trying to convince my team to use liveview over the current react. What are some of the points where one should consider us...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
ejpcmac
I have discovered Nix last month and I am currently on my way to migrating to it—both on macOS at home and the full NixOS distrubution at...
New
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
New
Qqwy
I would like to spark a discussion about the static access operator: .. For whom does not know: it is used in Elixir to access fields of...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement