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

Jayshua
I recently came across the javascript library htmx. It reminded me a lot of liveview so I thought the community here might be interested....
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
cvkmohan
The upcoming Phoenix 1.6 release looks very interesting. Became a habit to watch the commits - and - what they are bringing in. phx.gen...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
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
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
AstonJ
Can you believe the first professionally published Elixir book was published just 8 years ago? Since then I think we’ve seen more books f...
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
AstonJ
It’s been a while since we’ve had a thread like this, so what better way to kick off the year with :003: What does being an Elixir user ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
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
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement