r/sveltejs • • 5h ago

Change anything on this site – powered by svelte

Thumbnail levmiseri.com
13 Upvotes

A fun experiment where users can change or add anything to the site. Everything working very much thanks to the amazingness of Svelte.


r/sveltejs • • 3h ago

`opentui-svelte` ...Svelte bindings for opentui

2 Upvotes

TUI are all the rage right now and `opentui` it's a very nice way to build one in a simple way...BUT you are stuck with React or Solid which is fine but what if you could use something nicer? What if you could use Svelte?

Well now you can! `opentui-svelte` uses the brand-new custom renderers API to allow you to build TUIs using svelte as the declarative language to define them!

Give it a try a report any issues:

https://github.com/paoloricciuti/opentui-svelte


r/sveltejs • • 19h ago

SvelteKit: How do you share code that uses contexts with server/non-component code?

1 Upvotes

I've been developing a site that uses a component context for handling locales/localization. I want to use some of these calls in some +page.server.ts functions, outside of a Svelte context. What is the correct/idiomatic way to write code like this? Right now I have what I feel like is a big hack that does something like this:

export const [getLocaleContext, setLocaleContext] = createContext<{ code: string }>();

let override: string | null = null

export function overrideLocalization(overrideLocale: string, body: () => void) {
    override = overrideLocale;
    try {
        body();
    } finally {
        override = null;
    }
}

function getLocale() {
    if (override) {
        return override;
    } else {
        return getLocaleContext().code
    }
}

I try to make it safer with a wrapper function and try/finally but this still feels really flimsy. Is there a better way to handle this?