Clear riot tag cache to aid with testing #1875

adrianblynch opened this Issue Jul 4, 2016 · 8 comments


None yet

3 participants

adrianblynch commented Jul 4, 2016 edited


When unit testing tags I do something like the following:

const riot = require('riot')

// Test 1 - Render the child
const child = require('./child.tag')

const childHtml = riot.render(child)

console.log(childHtml) // Looks good
const riot = require('riot') // require caches riot.

// Test 2 - Render the parent

const parent = require('./parent.tag')

const parentHtml = riot.render(parent) // `child` is cached in riot

console.log(parentHtml) // Not what I want - See below...

In the above I want a way to not use the rendered child tag in the rendering of parent.

When child has already been rendered, the output of rendering parent is:

<parent><h1>Parent: </h1> <child><h2>I'm the child</h2></child></parent>

When what I want is:

<parent><h1>Parent: </h1> <child></child></parent>

I think what I'm asking for, is a way to clear any caching of tags in riot.

Is this possible?


  • Riot: 2.4.1
  • Node: 6.2.2
  • OS: Mac OSX 10.5.5

Possible tags

  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance
adrianblynch commented Jul 4, 2016 edited

I thought riot.vdom would be the thing to clear down, but in my example above, vdom remains an empty array.

My understanding is that this is populated on mount, not render.


Thinking about this some more, could removing riot from require's cache fix this issue?

GianlucaGuarini commented Jul 6, 2016 edited

the riot.unregister will be available in riot@3.0.0


It may be necessary to also clear the cache of expressions in tmpl


@aMarCruz could you please make a pull request?


@GianlucaGuarini , now the dev branch of riot-tmpl includes the public function clearCache.

Usage: tmpl.clearCache()


thanks @aMarCruz tmpl.clearCache() seems to clear the cache of all the expressions, will it be possible to clear the cache of all the expressions bound to a specific component?
In the end removes the implementation only of a specific tag


@GianlucaGuarini with the current implementation clearing the cache for specific tag is not possible.
There's no link to the source, the expression byself is the hash in the cache (a plain object) and it is shared between tags.

@GianlucaGuarini GianlucaGuarini added this to the 3.0.0 milestone Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment