Skip to content

Custom renderers support #15470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
benmccann opened this issue Mar 7, 2025 · 8 comments
Open

Custom renderers support #15470

benmccann opened this issue Mar 7, 2025 · 8 comments
Assignees
Labels
compiler Changes relating to the compiler feature request

Comments

@benmccann
Copy link
Member

Describe the problem

Svelte 4 had foreign namespace to support Svelte Native. This was removed in Svelte 5 as the approach was not compatible with the new compiler implementation: #12709

Describe the proposed solution

Add a custom renderer API to support things like:

Importance

nice to have

@benmccann benmccann added feature request compiler Changes relating to the compiler labels Mar 7, 2025
@Ocean-OS
Copy link
Contributor

Ocean-OS commented Mar 7, 2025

I'm not too knowledgeable in this topic, but perhaps there could be a map of method names and/or a map of handlers for different features? Example:

export const custom_renderer = {
    replacements: {
        state: 'ref' //$.state -> $.ref
    },
    handlers: {
        bind(prop, node, binding) {
            return x`$.bind(${node}, '${prop}', ${binding})`; //for bindings
        } 
    } 
} 

This could also include things like the boilerplate for each component.

@paoloricciuti
Copy link
Member

I'm not too knowledgeable in this topic, but perhaps there could be a map of method names and/or a map of handlers for different features? Example:

export const custom_renderer = {
replacements: {
state: 'ref' //$.state -> $.ref
},
handlers: {
bind(prop, node, binding) {
return x$.bind(${node}, '${prop}', ${binding}); //for bindings
}
}
}
This could also include things like the boilerplate for each component.

I think rather than a replacement for state (I think the reactivity should still be handled by svelte otherwise it's just a matter of syntax) we should have replacements for dom operations. That said we should probably also have a more general hook to transform the compiled code because there might be the need to setup stuff before the component code for example.

@Pronian
Copy link

Pronian commented Mar 7, 2025

Here is the Vue custom renderer API: https://vuejs.org/api/custom-renderer.html
And the SolidJS one: https://github.com/solidjs/solid/tree/main/packages/solid/universal

They are pretty similar. Do you think it would be good to make the Svelte API resemble something like that? (Would make porting existing solutions to Svelte easier)

@caracal7

This comment has been minimized.

@paoloricciuti paoloricciuti self-assigned this Mar 13, 2025
@cylicone
Copy link

+1 to this, I would love to see this work with Lynx!

@RoxDevvv
Copy link

RoxDevvv commented Apr 1, 2025

+1

@joshua1
Copy link

joshua1 commented Apr 9, 2025

+1 for this . any update please . This would be helpful for nativescript and lynx (potentially)

@paoloricciuti
Copy link
Member

+1 for this . any update please . This would be helpful for nativescript and lynx (potentially)

I'm actively working on this (well technically not now since I'm on vacation but you get the gist) since mainmatter (the company I work for) is sponsoring my work full time on this.

There's already a PR open #15538 to have a new templating mode that doesn't involve the template elementi which was obviously a blocker.

We are currently deciding on the best API for this, I kinda have a POC for one API and I'm building another POC for a different (imho slightly better API). It's coming! 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Changes relating to the compiler feature request
Projects
None yet
Development

No branches or pull requests

8 participants