I am working on arabic-russian dictionary, editable by users. And I faced an Issue, that I don’t understand.
I’m using blaze. And there is idea of structure:
Modal form opens ArticleForm for insert new Article. And then redirects page to new ArticlePage.
ArticlesList wraps couples of . One of them are visible, it depend on editMode parameter. ArticlePage passes array from one article ([articles.findOne]) to ArticlesList.
When I adds first article redirection works fine and page with new Article opens. There is only one ArticlePage template use, with one article instance. Redirection works from after-insert-hook (collections-hooks).
But when I repeat it at second time, there is an error Exception from Tracker recompute function:
And ArticlePage doesn’t render. And in console I see two ArticlePage calls, first with real data, and second with undefined. I can’t understand, from where appears this “undefined” article. If I reload empty page, it will be rendered well with new article.
UPD:
This error appears only when i’m trying to redirect from /articles/xxxx to /articles/yyyy . Redirect from main page / to /articles/xxxx works fine even many times.
You likely have a problem in one of your template helpers. Maybe you assume data is there when it is still being pushed down or data is simply not there.
Our template helpers usually have checks like this
Thank you for answer. I can’t understand what happens. In ArticlePage, I pass [article], array with one Article to ArticlesList, and when it happens from main page / , there is only one Article and all renders well . But when it is redirection from article/x to article/y , (from one ArticlePage to another) , in console.log i see Article appears 3 times, and third of them are undefined. I can’t figure out, from where it appears, and only when redirects in some route (but different :id) .
I shared the code too on stackoverflow
When I create article from main page ‘/’ , app redirect us to new article page with template “ArticlePage”. And there is only 1 console.log("articlePage article", article); , but when I create new article from article page, while redirection from one article to another (newly created) , there is 3 console.log("articlePage article", article); last of them “undefined”
I tried your example too. It doesn’t work for me. I have just rendered empty template, with no data.
Yes, there is no template exceptions, no errors in console.log, but also there is no rendered data at all. Because template renders empty data context articles = []
I still can’t understand how it relate to my use case. I want to return article, but there is undefined. Problem is not about i use article.field when it doesn’t exist. Problem is , that the article doesn’t exist at all. And I can’t return whole article.
Also, it looks like you are using findOne and then passing the result to another template/helper that expects an array. Kind of a weird solution. Why not just do:
Template.ArticlePage.helpers({
articles() {
const id = FlowRouter.getParam("id");
return Articles.find({ _id: id });
},
});
That way, you’ll either get an empty array or an array with one item, which should keep your template/helpers happy?
Or maybe rather: After you create the article from the article page, do you redirect it to the new article? Since you use the router params to feed it, the router must know what you want to display.