Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey, sorry to drop a bunch of changes on you, but I encountered an issue, had to dig in deep to figure out what was going on, and then needed to change a bunch of stuff to fix my bug. Here's an overview:
My original problem came when I tried to pass an object as a variable into a
component_block
tag, then have the context method process it into a handful of context variables. Long story short, this wasn't working, because the context method sometimes gets called twice, with the outputs of the first call being the inputs of the second call. That works fine if the context method doesn't transform its arguments, but fails when the context variables are different than the component params.My fix was essentially just to have a single place for calling the context method (in the ComponentNode's render method), then to pass the context itself into the component's render method. I think this is more straightforward and fixed my problem nicely. As a side benefit, I think it will fix the CSRF problem in #12, at least when component_block is used. Previously, the non-slot portions of the component were being rendered with a bare
Context
, not aRequestContext
. I reworked it so that the component renders itself with the context (presumably a RequestContext) that the template engine passes to it, so hopefully that will help. I think using a component tag still won't work, because that tag doesn't get a context. You could fix that by making it atakes_context
tag, but I didn't make that change.I also made some assorted tweaks as I was studying the code to help me follow better. I left those in this PR, but you can obviously disregarded them if you don't think they're helpful.
I added a bunch of tests to look at various permutations of context, and everything passes. That said, I can't swear that these changes won't break someone's code in some subtle way.
I hope these are helpful, and I'm happy to provide more explanation about anything I did.