Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

can't use a page part twice in the same context #78

Closed
eostrom opened this Issue Dec 30, 2009 · 4 comments

Comments

Projects
None yet
2 participants
Member

eostrom commented Dec 30, 2009

I just ran into this, but Dmitry Belitsky previously reported it and John Muhl reduced his test case (http://www.mail-archive.com/radiant@radiantcms.org/msg05911.html). Here's a further reduced test case:

  1. Create a page with body and extended parts.
  2. Enter this for the body: <r:content part="extended"/><r:content part="extended"/>

On 0.9.0rc1, I get this error: "Recursion error: already rendering the `extended' part." But this isn't recursion, it's just repetition.

Owner

seancribbs commented Dec 30, 2009

Does it only happen with parts other than 'body'? See here: http://github.com/radiant/radiant/blob/master/spec/models/standard_tags_spec.rb#L270

Member

eostrom commented Dec 30, 2009

It happens with parts named 'body' or named something else.

After further digging: The key difference between your test case and mine is that in yours, the repetition happens in the global context; in mine, it happens one level down, inside of a named part.

What's happening in the case I described:

  • The layout wants to render the body part. The global context has no rendered parts list, so it starts one and adds 'body'.
  • The body part wants to render the extended part. It inherits the rendered parts list from the layout context, and adds 'extended'.
  • The body part wants to render the extended part again. It inherits the rendered parts list from the layout context, and 'extended' is already there, so it falsely detects recursion.

In the test case you linked to:

  • The global context renders an unnamed string, and so never creates a rendered parts list.
  • The unnamed string wants to render the body part, and has no rendered parts list, so it starts one and adds 'body'.
  • The unnamed string wants to render the body part again, and still has no rendered parts list (the previously created one was thrown away with the first body part's context), so it starts one and adds 'body'.

I may not be getting all the terminology right. But the point is, the rendering parts stack isn't strictly local, and so it doesn't automatically get popped when the tag.locals stack is.

My previous fix gets the job done, but here's one that (a) uses tag.globals, since you're sharing the data structure once you get into part rendering anyway, and (b) integrates better with your existing test case.

rx pushed a commit to voomify/radiant that referenced this issue Jul 19, 2011

Fixed overzealous recursion prevention. Closes #78.
The content tag checked whether a given part *has been rendered*, but
to prevent recursion, we just need to check whether the part *is being
rendered*. So when we're done rendering a part, we remove it from the
danger list.

rx pushed a commit to voomify/radiant that referenced this issue Jul 19, 2011

Merge branch 'master' of github.com:radiant/radiant
* 'master' of github.com:radiant/radiant:
  Fixed overzealous recursion prevention. Closes #78.
  Explain the gem naming convention
  Use git info for extension.rb, if available
  Generate Jeweler config for new extensions
  Copy rake tasks from gem extensions on radiant:extensions:update_all
  Spec cleanup
  Enforce radiant-*-extension naming in gems
  Support for radiant-*-extension gem naming
  Remove 00_ style extension prefixes

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment