question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make getCssString work with custom theme

See original GitHub issue

Is your feature request related to a problem? Please describe. I am trying to server-side render a custom theme, but it seems like getCssString only renders the default css vars.

Describe the solution you’d like Stitches could pick up on custom themes created just like it does with calls to the css function, and render that theme out as well. Then I could just make sure that I attach the correct classname to the body at SSR.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jonathantnealcommented, Sep 9, 2021

To get a theme created with createTheme() to render into getCssText then it needs to be referenced somehow.

import { createStitches } from 'https://cdn.skypack.dev/@stitches/core'

let { getCssText, createTheme } = createStitches({
	theme: {
		colors: {
			blue100: '#0000ff',
		},
	},
})

let altTheme = createTheme({
	colors: {
		blue100: '#3333ff',
	},
})

getCssText() // will not contain altTheme

// either of these
altTheme.toString()
altTheme.className

getCssText() // will now contain the CSS for altTheme

It works this way to prevent unused CSS from being compiled.

2reactions
AndrewPrifercommented, Sep 24, 2021

Oh I completely missed your answer @jonathantneal, thanks a ton!

@peduarte I would never have expected this to be the solution to what I see as quite a normal use case, the behavior here doesn’t really seem “intentional” haha. Although my problem specifically is solved, do you think this use case could be better supported, through documentation, and (ideally, I think) a more explicit API?

Read more comments on GitHub >

github_iconTop Results From Across the Web

API - Stitches.dev
A function to create a component including its styles and variants. ... You can use this function if you need to add default...
Read more >
How to Create a Custom WordPress Theme - Full Course
Learn how to create a custom WordPress theme. You will learn a process that you can use to convert any HTML/CSS template into...
Read more >
Theme tokens not working · Discussion #567 · stitchesjs/stitches
A few things: The config you're passing in is a copy/paste from the docs which isn't really a recommended config. It's more to...
Read more >
Using CSS custom properties to apply themes in JavaScript or ...
setProperty('--my-epic-var', someValue);. Let's work through the steps and build up a dynamically loaded theme for ourselves. Building a custom ...
Read more >
Theme | Laravue
This project is based on the element-ui default visual style. If you have additional requirements for visual style, you can follow the official...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found