Because of the extreme diversity in voting methods in the US (it varies not only by state, but by county within the state) it's impossible to accurately make any generalization about voting in the US. For example, in my parents' county in Wisconsin, you show up at the polling place, they check you off the list of registered voters, and they hand you a ballot with no individual markings at all. Once you finish filling it out, you put it in a box with the other identical ballots, to be counted later. It's as anonymous as you could possibly ask for, except that they know that someone claiming to be you showed up and voted.
As far as party registration goes, is that required where you are? Because if so that's insane and the government there needs to change that. Everywhere I've lived you don't need to register any kind of party affiliation (and indeed some places you couldn't), you just register as a voter and you're good. Maybe it's different where you are, but if so just be aware that it is (thankfully) not universally done wrong in the way you describe.
Party registration isn't required (I'm unaffiliated, for example) but enough people do it that you can make a reasonable prediction of how a precinct is going to vote before they actually vote. This is the input data for gerrymandering: you don't need to know every single voter, as soon as you get a statistical sample you know how the area is likely to vote, and then you can construct districts out of precincts such that there's a safe margin of victory for each one.
Unfortunately, in that case there isn't much to be done. I think those people shouldn't do that, but if they insist I don't see how they could be stopped.
Many states require party registration to vote in primary elections, and in states like California the primary is the only election that realistically matters.
(1) California does not require party preference to vote in primaries generally;
(2) California primaries are not (except for the Presidential primary) party nominating elections, they are essentially the open first-round of a two-round general election. (Basically, it is majority/runoff except that there is always a runoff even with a first-round majority.)
(3) For the Presidential primary, California does not require party registration to vote, but does prohibit party-registered voters from voting in cross-party primaries; it is the party (not the state) the decides whether their primaries are open to “no party preference" voters (of the six parties with permanent ballot access in California, the Republican, Green, and Peace & Freedom parties do not allow NPP voters in their presidential primaries, while the Democratic, Libertarian, and American Independent parties do allow them.)
As far as party registration goes, is that required where you are? Because if so that's insane and the government there needs to change that. Everywhere I've lived you don't need to register any kind of party affiliation (and indeed some places you couldn't), you just register as a voter and you're good. Maybe it's different where you are, but if so just be aware that it is (thankfully) not universally done wrong in the way you describe.