-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locals are not being overridden when passed via req.options.locals #3500
Comments
Hey @megakoresh, would you mind adding information about your Sails, Node, and NPM versions to this issue? In this case, it looks like the knowledge of which view engine (default EJS, jade, etc) you're using would also be helpful. Thanks! |
No, sailsbot, I do not think it would be helpful, since the issue has to do with passing variables around, and switching the view engine does not do anything. But have it anyway: |
Hey @megakoresh- different view engines interpret locals differently. For example, EJS allows you to provide configuration for the view engine itself by passing them amongst the locals (believe it or not x_x). Anyways, just worth pointing out that in some cases, this can make a huge difference. Would you post your version of Jade in this issue just for future reference? Part of the reason for collecting as much information about dependency versions as possible is to provide a trail of clearly documented breadcrumbs if we find ourselves hunting down semi-related issues in the future. My guess is this could be an issue stemming from sails/lib/hooks/views/res.view.js Line 153 in 61a72d6
_.defaults() -- and although the deep merge was never officially documented behavior, I'll document the move to a shallow merge as a breaking change in 0.12 just to be safe. Took a step in that direction w/ 5861f65, but we also need a test for this in core.
Before going too much further down this road though, would you verify something for me in your local project?
Thanks again for your help! |
As a matter of fact it isn't messed up. When I enter that in console it doesn't return the navlist at all - only the globally available locals (and before you ask - yes, I did try removing them to no effect). Logging I updated my sails installation to the latest version from github with your change, but it didn't fix the issue. By the way if you are wondering what My Jade version is 1.11.0. Now I need to sleep, it's almost 1am... Will be back at this tomorrow. UPDATE: Despite my head feeling like an atomic bomb ready explode I stuck around am glad I did: I found the problem, though not the logic behind it. When I returned the results from the database to the |
@megakoresh hmm, perhaps a global leak? If (Leaving this open to remind us to update the docs for |
Added documentation to 0.12 branch to clarify that this is a shallow merge; re balderdashy/sails#3500 (comment)
I have encountered a very weird bug. I have a policy that runs before every request generating a quick navigation list for the site's content. The nav list is basically a nested categorized list of the format
And so on...
The policy creates the list under the
req.options.locals.navlist
. The problem is that when I change a category of something, it will still show up in it's old category as well as the new one, until I re-lift the app. If I log the object from a view it shows that after re-arranging the items old entry is being kept in memory anyway and the new correct list simply gets added on top. If I log the list from the policy itself, there are no problems, the list is correct.Policy code is like so:
Then in my controller I have it like
Is this a bug? I would think that if I pass a new variable by the same name the old should be overridden. I also have some global locals (thats a funny phrase) for all views under
config.views.locals
setting.The text was updated successfully, but these errors were encountered: