react-live icon indicating copy to clipboard operation
react-live copied to clipboard

Theme not applied [v3.0.0]

Open areddon opened this issue 2 years ago • 1 comments

When supplying the theme to the LiveProvider, the styles it contains are incorrectly disregarded.

See the following line.

props.className is coming in as undefined, while _style object contains theme.plain and therefore the expression will be true, yielding {} when you want _style.

areddon avatar Feb 15 '22 18:02 areddon

hey @areddon -- thanks for opening this issue! we're not aware of any issues passing theme down 🤔

it's covered in one of our StoryBook stories (which passes in the default theme here)

are you able to provide an example reproduction of what you're seeing? thanks!

jpdriver avatar Apr 11 '22 15:04 jpdriver

I've noticed this as well when updating react-live from 2.4.1 to the latest (3.1.1). I tried passing the vsDark theme which worked in v2, but now it looks like this:

vsdark theme on v2 Screen Shot 2022-10-18 at 2 49 59 PM

vsdark theme on v3 image

it looks like the background color and the font-family isn't getting applied properly but the text colors look correct to me!

oliviadawd avatar Oct 18 '22 18:10 oliviadawd

Our prism-react-renderer theme object is also not rendering correctly, after upgrading from 2.4.1 to 3.1.1. To be specific, the issues seems limited to background color not propagating.

theme.js

var theme = {
  plain: {
    backgroundColor: "#1f2a36"
  }
  ...
}

Before ([email protected])

Screenshot 2022-12-28 at 10 17 39

After ([email protected])

Screenshot 2022-12-28 at 10 20 22

GilmarLira avatar Dec 28 '22 18:12 GilmarLira

hey @areddon -- thanks for opening this issue! we're not aware of any issues passing theme down 🤔

it's covered in one of our StoryBook stories (which passes in the default theme here)

are you able to provide an example reproduction of what you're seeing? thanks!

@jpdriver, your StoryBook uses a styled Editor, which is defining a background here. It is therefore not really testing the backgroundColor coming from the theme.

That is likely obscuring the issue @oliviadawd and myself are seeing.

GilmarLira avatar Dec 28 '22 18:12 GilmarLira

Changing this line to use LiveEditor instead will reveal the problem: https://github.com/FormidableLabs/react-live/blob/5123cfd12de4cfafa7c65e59a967927a27eaca70/stories/Live.js#L208

GilmarLira avatar Dec 28 '22 19:12 GilmarLira

Confirmed with following diff in default live example:

diff --git a/stories/Live.js b/stories/Live.js
index d29520b..29350de 100644
--- a/stories/Live.js
+++ b/stories/Live.js
@@ -226,6 +226,7 @@ export const Default = DefaultTemplate.bind({});
 Default.args = {
   ...defaultControls,
   code: code,
+  theme: theme,
 };
 
 export const FunctionExample = StyledPreviewTemplate.bind({});

Setting theme.plain.color does work, but setting theme.plain.backgroundColor does not.

ryan-roemer avatar Dec 30 '22 18:12 ryan-roemer

Thanks for fixing this @ryan-roemer! I didn't realize it was fixed until I read through the releases, do you mind closing the issue?

cjseattle avatar Jun 09 '23 19:06 cjseattle