Skip to content
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

Style attribute client vs server rendering inconsistency #2310

Open
frenzzy opened this issue Sep 26, 2024 · 0 comments
Open

Style attribute client vs server rendering inconsistency #2310

frenzzy opened this issue Sep 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@frenzzy
Copy link
Contributor

frenzzy commented Sep 26, 2024

Describe the bug

The following JSX:

<button style={{
  'background-color': count() ? "white" : '',
  color: count() ? "black" : null,
  display: count() ? "block" : undefined,
}} />

compiles to the following SSR code:

var _v$ = count() ? "white" : '',
   _v$2 = count() ? "black" : null,
   _v$3 = count() ? "block" : undefined;
 _v$ !== _p$.e && ((_p$.e = _v$)  != null ? _el$.style.setProperty("background-color", _v$) : _el$.style.removeProperty("background-color"));
_v$2 !== _p$.t && ((_p$.t = _v$2) != null ? _el$.style.setProperty("color", _v$2)           : _el$.style.removeProperty("color"));
_v$3 !== _p$.a && ((_p$.a = _v$3) != null ? _el$.style.setProperty("display", _v$3)         : _el$.style.removeProperty("display"));

and the following CSR code:

_$ssr(
  _tmpl$,
  _$ssrHydrationKey(),
    "background-color:" + (count() ? "white" : "") +
  (";color:"            + (count() ? "black" : _$escape(null, true))) +
  (";display:"          + (count() ? "block" : _$escape(undefined, true))),
  _$escape(count())
);

The problem is that CSR produces the expected HTML:

<button></button>

but SSR produces invalid HTML markup (from a validator’s point of view):

<button style="background-color:;color:null;display:undefined"></button>

Your Example Website or App

https://playground.solidjs.com/anonymous/9942822a-9d64-4687-a2f0-e6944534159f

Steps to Reproduce the Bug or Issue

  1. Open the playground link.
  2. Select different compile modes and compare the output.

Expected behavior

I expect SSR to avoid rendering styles with null and undefined values, similar to CSR.

It would be ideal if the server side did not render style attributes with values of undefined, null, or ''.

Additionally, it would be helpful if an empty string ('') also caused the removal of the corresponding style attribute on the client side.

Screenshots or Videos

No response

Platform

  • OS: any
  • Browser: any
  • Version: 1.9.0

Additional context

No response

@ryansolid ryansolid added the bug Something isn't working label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants