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

Don’t join nil classes into classes string #132

Merged
merged 1 commit into from
Oct 3, 2016
Merged

Don’t join nil classes into classes string #132

merged 1 commit into from
Oct 3, 2016

Conversation

tonsky
Copy link
Contributor

@tonsky tonsky commented Oct 2, 2016

It started with @fotoetienne noticing in tonsky/rum#99 that

[:.c1 { :class nil }]

and

[:.c1 { :class (when false "...") }]

yield different results. This is unfortunate, because in Rum’s server-side rendering, I do not use precompilation step and render HTML based on its value only.

In Sablono, on the other hand, end result might depend on the compilation mode selected:

(macroexpand '(html [:.c1 { :class nil }]))
;; => (js/React.createElement "div" #js {:className "c1"})
;; => <div class="c1"></div>

(macroexpand '(html [:.c1 { :class (when false "...") }]))
;; => (js/React.createElement "div" #js {:className (sablono.util/join-classes ["c1" (when false "...")])})
;; => <div class="c1 "></div>

(note the extra space after c1).

This patch fixes the issue by patching sablono.util/join-classes to ignore nils and bringing it on par with the strategy used in all-literal expansion of html macro.

I thing you’ll agree that precompilation strategies should be there for speed optimization only, and should yield totally equal results no matter which mode is used.

@r0man r0man merged commit 5855eb6 into r0man:master Oct 3, 2016
@r0man
Copy link
Owner

r0man commented Oct 3, 2016

@tonsky Thanks!

@r0man
Copy link
Owner

r0man commented Oct 3, 2016

Released as 0.7.5.

@tonsky
Copy link
Contributor Author

tonsky commented Oct 3, 2016

Thanks!

On Mon, Oct 3, 2016, 19:25 r0man notifications@github.com wrote:

Released as 0.7.5.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#132 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AARabGDd3l35v3QJPlqZ37PwA8HpC-2Cks5qwPQxgaJpZM4KMFeS
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants