Skip to content

Commit

Permalink
Closes lift#1158. data-lift no longer causes stack overflow. Transien…
Browse files Browse the repository at this point in the history
…tSnippet trait added
  • Loading branch information
dpp committed Dec 12, 2011
1 parent 0556f9f commit 2e18c77
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions web/webkit/src/main/scala/net/liftweb/http/LiftSession.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1540,8 +1540,9 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
first(LiftRules.snippetNamesToSearch.vend(tagName)) {
nameToTry =>
val ret = findSnippetInstance(nameToTry)
// Update the snippetMap so that we reuse the same instance in this request
ret.foreach(s => snippetMap.set(snippetMap.is.updated(tagName, s)))
// Update the snippetMap so that we reuse the same instance in this request (unless the snippet is transient)
ret.filter(TransientSnippet.notTransient(_)).foreach(s => snippetMap.set(snippetMap.is.updated(tagName, s)))

ret
}
}
Expand Down Expand Up @@ -2241,7 +2242,7 @@ private object SnippetNode {
if (p.pre == "l" || p.pre == "lift") && p.key == "parallel"
=> par = true

case up: UnprefixedAttribute if up.key == "lift" => // ignore
case up: UnprefixedAttribute if up.key == "lift" || up.key == "data-lift" => // ignore

case p: PrefixedAttribute
if p.pre == "lift" && p.key == "snippet"
Expand Down
25 changes: 25 additions & 0 deletions web/webkit/src/main/scala/net/liftweb/http/StatefulSnippet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,31 @@ trait DispatchSnippet {
def dispatch: DispatchIt
}

/**
* This trait indicates if the snippet instance should be kept around for the duration of
* the Request. There are cases when you don't want a snippet to be kept around.
*/
trait TransientSnippet {

/**
* Calculate if this snippet should be treated as transiet.
*/
def transient_? = true
}

/**
* The companion object to the TransientSnippet trait
*/
object TransientSnippet {
/**
* Compute if the instance should be treated as transient
*/
def notTransient(obj: Any): Boolean = obj match {
case t: TransientSnippet => !t.transient_?
case _ => true
}
}

/**
* Mix this snippet into any snippet. If the snippet is invoked in response to a
* stateless request, then the behavior method is called with the method name of
Expand Down

0 comments on commit 2e18c77

Please sign in to comment.