Exploring Meteor as a newcomer has led me to encounter a sticky issue.
I've integrated React Router in an attempt to display a theme based on the URL /(:userId). The goal is to show the current user's theme if no specific userId is provided, and default to a standard theme if there is no active user.
The behavior I'm experiencing seems sporadic. At times, the correct theme is displayed, while other times it throws 'undefined' when trying to read the themeColor data, even though the data is present. Upon inspecting with console.log, I can confirm that the correct Id is always received, yet findOne may still return undefined. This inconsistency becomes evident especially when switching between different URLs (/xyz) and reverting back to the default one (/).
After checking the console output, it appears that the userId matches the owner of both themeColor and themeTextColor.
In my setup, I am utilizing React, React-router, autopublish, with insecure removed.
getMeteorData() {
var currentViewedPageId = this.props.params.userId? this.props.params.userId:(Meteor.userId()?Meteor.userId():false);
console.log(currentViewedPageId); //Always correct
console.log(Personalization.findOne({owner: currentViewedPageId}).themeColor); //Can be undefined at times
if(currentViewedPageId)
{
return {
currentUser: Meteor.user(),
themeColor: Personalization.findOne({owner: currentViewedPageId}).themeColor,
themeTextColor: Personalization.findOne({owner: currentViewedPageId}).themeTextColor
};
}
return {
currentUser: Meteor.user()
}
},