Incorrect render nested tags in loops with IF condition on server-side mode #1839

Closed
believer-ufa opened this Issue Jun 20, 2016 · 1 comment

Projects

None yet

2 participants

@believer-ufa
believer-ufa commented Jun 20, 2016 edited

While Riot.js render nested tags in loops in server-side mode, it renders them in any situation, regardless of the if conditions. In "browser" render mode everything works as excepted.

Example on plnkr that shows that in browser side everything works fine

Source code for serverside render that works incorrect:

render.js

var riot = require('riot')
require('./tagToRender.tag')
var html = riot.render('tag-to-render')
console.log(html)

tagToRender.tag

<tag-to-render>
    <p>tag content</p>
    <second-tag each="{ el in [1,2,3,4] }" if="{ false }" ></second-tag>
</tag-to-render>

<second-tag>
    <p>paragraph</p>
</second-tag>

Serverside render result on my machine:

<tag-to-render>
  <p>tag content</p>
  <second-tag><p>paragraph</p></second-tag>
  <second-tag><p>paragraph</p></second-tag>
  <second-tag><p>paragraph</p></second-tag>
  <second-tag><p>paragraph</p></second-tag>
</tag-to-render>

Riot.js version: 2.4.1

How would you tag this issue?

  • Bug
@believer-ufa
believer-ufa commented Jun 22, 2016 edited

Temporary solution for this problem which I invented: create method to get array of items. And check conditions in this method. If conditions dont accepted, just return an empty array.

With this approach everything work fine ))

Example:

<tag-to-render>
    <p>tag content</p>
    <second-tag each="{ el in getItems() }"></second-tag>

    <script>
        getItems() {
            return (conditions)
                ? [1,2,3,4]
                : []
        }
    </script>
</tag-to-render>

<second-tag>
    <p>paragraph</p>
</second-tag>
@GianlucaGuarini GianlucaGuarini added a commit that referenced this issue Jun 23, 2016
@GianlucaGuarini GianlucaGuarini closes #1839 d1f79f8
@GianlucaGuarini GianlucaGuarini added this to the 3.0.0 milestone Jun 23, 2016
@GianlucaGuarini GianlucaGuarini added a commit that referenced this issue Jul 12, 2016
@GianlucaGuarini GianlucaGuarini Merge branch 'bug/1850' into dev
* bug/1850:
  closes #1839
a7ae648
@GianlucaGuarini GianlucaGuarini added a commit that closed this issue Aug 20, 2016
@GianlucaGuarini GianlucaGuarini closes #1839 d048b68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment