As others have said before: this is hugely timing, lab, project, and journal dependent. Really, your best bet is to put forth the effort... and a lot of luck. I don't have as much experience as many others on this forum, but I'll just share my observations. ~the following is anecdotal evidence only~
1. Timing: coming on at the right time is key. If you can come onto the end of a project, analyze the data, and crank out some figures, you ought to be golden. However, more often than not, undergrads will be placed on new projects where they can prove their worth... hence more data collection and less figure generating. While landing such a project can be sheer luck, I found that the projects set aside for summer fellowship students (think SURF, Amgen, etc.) are typically more "mature" projects, so you may be able to tackle a substantial chunk of a project that will
eventually make its way to publication. The PIs at my summer program loved to make their summer students look really good for the end-of-program poster competition, so they didn't stick people onto dead-end projects.
😉 They'll also be paying you at these programs, so they'll want to get some worthwhile research out.
2. Lab: you're going to start off at the bottom, but will you be given the chance to work your way up? There was one lab at my undergrad that was infamous for letting everyone on and would have an assembly line of 50+ undergrads pumping out data... so the prospect of an authorship created fierce competition (and lots of pettiness). In the end, some people were tacked onto papers pretty much arbitrarily. They'd usually end up with something like 20th author, by the time the 12 different masters students were factored in, and would never actually touch the manuscript. On the other hand, my lab was small and I was the only undergrad (not even any grad students either!), so I got an unparalleled level of mentorship. My superiors also really wanted me to learn more, become fully independent, and publish before matriculating to med school. Honestly, my mentors taught me more than my 4 years of undergrad coursework did. I credit my MCAT BS score entirely to all the literature review and experimental design they helped me with.
Regarding lab drama: I feel horrible for the students who put out substantial effort in the lab, only to find they have been squeezed off of a paper for political reasons. My best suggestion is that if a lab doesn't "click" with you, leave when it's still early. Lab drama ain't worth your time. Seriously. Lab drama is the devil and has the potential to follow you around for the rest of your professional career.
3. Project: is it bench, clinical, translational, etc? This can definitely impact the duration of a research project. I can only speak to bench-work, but there are projects in their 5th year running full-steam at my lab... and still not yet published. A project I was published on took about 3+ years of effort (though I was only working on it part-time for 2 years). Also, if your project requires a lot of collaboration with other labs this may either speed up or slow down the process. A lot of my work will never end up being published because a) it catastrophically failed or b) the project was not classified for public release.... in fact, the majority of work I did will never end up in press because it failed. I'm also primary author on a internal govt. report, but couldn't put it on my app. C'est la vie. The experience was worth more than the publications.
4. Journal: lots of variability here. Sometimes you'll be accepted off the bat, other times you'll fall into limbo with multiple edits, or maybe you'll even have to go from journal to journal, begging for acceptance. You may get a reviewer with a vendetta against your PI.

What can you do? I wish I knew.
In short: My research experience was rather atypical. I did a few months in an undergrad lab (basically an unpaid scut monkey), disliked the research/environment, and applied for a paid traineeship in a government lab my sophomore year.
Pros: Hands down best experience in my undergrad career. I was the only undergrad, so I was mentored continually by staff scientists and actually worked alongside my PI. As the sole undergrad you kind of become their little project and they sink a lot of time/energy into your learning experience. The projects I worked on were also utterly amazing... at a few of my interviews I was asked
only about my research. In fact, I got my current gap year job thanks to the people I met throughout my undergrad research.
Cons: with the downturn in govt. educational program funding, the program I was hired on under is now defunct and such positions are extremely rare... my PI doesn't even have undergrads now. Also, most of the defense-related projects were not allowed to be published (hence no poster presentations or conferences), though it is cool to say you had a security clearance. Finally, because I wasn't at a degree-granting institution, there was no "push" to get papers out for PhD students... and so manuscripts could take their sweet 'ol time. They still are taking their time...
😉
tl;dr: do research. It's cool, but it can also suck. Pubs are the (rare) little cherry on top.