Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Displaying Code Snippets in SolidJS

The SolidJS ecosystem, while growing, is still relatively small compared to frameworks like React. This can sometimes make it challenging to find tools and solutions specific to SolidJS. Recently, I participated in the #SolidStart2024…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

The SolidJS ecosystem, while growing, is still relatively small compared to frameworks like React. This can sometimes make it challenging to find tools and solutions specific to SolidJS. Recently, I participated in the #SolidStart2024 hackathon, where I created an app on the SolidStart framework. Through this experience, I encountered a need for a lightweight way to display code snippets within the app.









Introduction



In building my app, I needed to display some code snippets in a readable format, but I didn’t want to add the overhead of a full-fledged code editor like CodeMirror. While CodeMirror is a powerful option, it felt like overkill for simple code block formatting needs. Instead, I found a solution that’s more suitable for the SolidJS ecosystem: Shiki.




💡 Attention SolidJS fans: If you’re a SolidJS or SolidStart enthusiast, we would love your support! Check out our hackathon project, Spotter by Emmanuel Ajike, on SolidHack 2024. Your vote means a lot, and it costs nothing to participate!










API Observability and Spotter.dev



API observability is not the same as logging. With logging, you often have to know in advance what to log and where to look. Observability, on the other hand, provides a full picture of the data flowing through your API, which is crucial for production environments where users rely on your product.



As developers in 2024 and beyond, building robust APIs is critical for delivering real-world solutions. With this in mind, I created Spotter.dev—a developer tool designed to enhance the experience of working with SolidStart REST APIs and microservices. Spotter provides a clean overview of each API endpoint, making it easy to understand the data entering and leaving your services, which ultimately leads to better user experiences.









Using Shiki for Code Highlighting



To format code snippets without the weight of a code editor, I chose Shiki. Shiki is a tool that formats code as HTML, making it simple, intuitive, and easy to use. Here’s a quick example:




const code = `console.log('Shiki is great.')`;

const html = (await codeToHtml(code, {
lang: "javascript",
theme: "slack-dark",
})) as string;






In this example, the codeToHtml function takes the code as the first parameter and a configuration object as the second. The configuration specifies the language and theme.



One drawback is that Shiki is asynchronous, which can introduce a delay when rendering code. By using some SolidStart features, we can optimize rendering and minimize this delay:





  • createResource – Fetches the highlighted HTML.


  • onCleanup – Clears any previous HTML content from the wrapper.


  • createEffect – Renders the code.



Here’s the full CodeBlock component I built:




import { codeToHtml } from "shiki";
import { createResource, Suspense, onCleanup, createEffect } from "solid-js";
import { cn } from "~/lib/utils";

const CodeBlock = (props: {
code: string;
lang: "json" | "javascript";
class?: string;
}) => {
let containerRef!: HTMLDivElement;

// Fetch the highlighted HTML
const [html] = createResource(async () => {
return (await codeToHtml(props.code, {
lang: props.lang,
theme: "slack-dark",
})) as string;
});

// Clear previous HTML before setting new content
onCleanup(() => {
if (containerRef) containerRef.innerHTML = "";
});

// Render the highlighted HTML
createEffect(() => {
if (html() && containerRef) {
containerRef.innerHTML = html() as string;
}
});

return (
<div
ref={containerRef}
class={cn(
"[&>*]:p-3 [&>*]:rounded-lg [&>*]:font-mono [&>*]:text-sm",
props.class
)}
></
div>
);
};

export default CodeBlock;









Spotter.dev SolidHack2024









Usage Example



To use the CodeBlock component, simply wrap it with a Suspense component to handle loading states. Here’s an example:




<Suspense fallback={<div>Loading Code</div>}>
<CodeBlock code={code} lang="json" />
</Suspense>






This approach allows you to display highlighted code snippets with minimal overhead, integrating nicely into the SolidStart framework.









Conclusion



I hope this blog post offers a helpful solution for displaying code snippets in SolidJS. With Shiki, you don’t need the extra weight of Codemirror. Instead, you get a simple, effective tool that meets most needs without overcomplicating your app.



Thank you for reading, and if you find this helpful, please consider supporting our project, Spotter by Emmanuel Ajike, on SolidHack 2024! Your vote would mean a lot to us.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Displaying Code Snippets in SolidJS

Thematisch verwandte Begriffe: Displaying, Code, Snippets, SolidJS · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-18163 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick