Star Trek may have been ahead of its time for American television; it was not ahead of its time for science fiction. You may wish to read the article "Race in SF" in the Encyclopedia of Science Fiction. I will just give a few examples of the treatment of race in classic science fiction.
1935: Odd John by Olaf Stapledon; you can read it at Project Gutenberg Australia. Stapledon was a very influential writer; he originated many of the familiar themes of science fiction. Odd John is a story of tension and conflict between two races: Homo sapiens and Homo superior. (The term Homo superior was coined in this work.) The Homines superiores, few in number and scattered around the world, come in various shades:
Looking at the slight naked figures of various shades from Ng-Gunko's [n-word]-brown to Sigrid's rich cream, all seated round the table and munching with the heartiness of a school treat, I felt that I had strayed into an island of goblins. This was in the main an effect of the two rows of large heads and eyes like field-glass lenses, but was accentuated by the disproportionately large hands which were busy with the food. The islanders were certainly a collection of young freaks, but one or two of them were freakish even in relation to the standards of the group itself. There was Jelli with her hammer-head and hare-lip, Ng-Gunko with his red wool and discrepant eyes, Tsomotre, a Tibetan boy, whose head seemed to grow straight out of his shoulders without the intervention of a neck, Hwan Tê, a Chinese youngster, whose hands outclassed all the others in size, and bore, in addition to the normal set of fingers, an extra and very useful thumb.
Since the death of Yang Chung the party comprised eleven youths and boys (including Sambo) and ten girls, of whom the youngest was a little Indian child. Of these twenty-one individuals, three lads and a girl were Tibetan, two youths and two girls were Chinese, two girls were Indian. All the others were of European origin, except Washingtonia Jong. I was to discover that of the Asiatics the outstanding personalities were Tsomotre, the neckless expert in telepathy, and Shên Kuo, a Chinese youth of John's age who specialized in direct research into the past. This gentle and rather frail young man, who, I noticed, was given specially prepared food, was said to be in some ways the most "awakened" member of the colony. John once said half seriously, "Shên Kuo is a reincarnation of Adlan."
1951: "Dark Interlude", a much-reprinted and translated short story by Fredric Brown and Mack Reynolds; originally published in the January 1951 issue of Galaxy Science Fiction, one of the leading science-fiction magazines of the time; you can read it at the Internet Archive. It tells of a visitor to the Twentieth Century from forty centuries in the future, a time when there are no more racial differences, who married a white woman in the rural United States. His brother-in-law confesses a murder to the sheriff:
"I got to asking him some questions about things in his time and after a while I asked him how they got along on race problems and he acted puzzled and then he said he remembered something about races from history he'd studied, but that there weren't any races then.
:He said that by his time—starting after the war of something-or-other, I forget its name—all the races had blended into one. That the whites and yellows had mostly killed one another off and that Africa had dominated the world for a while, and then all the races had begun to blend into one by colonization and intermarriage and that by his time the process was complete. I just stared at him and asked him, 'You mean you got [n-word] blood in you?' and he said just like it didn't mean anything, 'At least one-fourth.'"
"Well, boy, you did just what you had to," the sheriff told him earnestly, "no doubt about it."
"I just saw red. He'd married Sis; he was sleeping with her. I was so crazy-mad I don't even remember getting my gun."
"Well, don't worry about it, boy. You did right."
1967: Galactic Odyssey by Keith Laumer; full text available from Baen Books. Here is a plot synopsis from Wikipedia:
Down on his luck college dropout Billy Danger shelters from a sleet storm in what he thinks is a corn silo, but which turns out to be a spaceship containing a party of upper-class hunters from the planet Zeridajh, from half-way across the Milky Way. They take him on as a gun-bearer, and after landing on a desert world, the two men are both killed, and Billy is left alone with the beautiful Princess Raire. Since only the men knew the password to re-enter the spaceship they are effectively marooned. They signal for help via a radio they find in an abandoned spaceship that has crashed into a nearby ravine. Unfortunately some none-too-friendly aliens answer the call and kidnap the princess, and then, clumsily, try to kill Billy. He survives, and is nursed back to health by a giant tabby cat who survived from the derelict spaceship. A more friendly bunch of aliens arrive and give him a ride to another planet, where he sets out in his quest to find the princess. He has many adventures across the galaxy, including being captured on a spying mission, where he is forced to ransom his friends' lives by giving up his right eye. Eventually he finds the princess, but she has been enslaved. He buys her freedom, and that of another human, but the human slave kidnaps the princess and he is forced into slavery himself. He eventually escapes, revenges himself on his enemies, and flies away with the princess.
There is nothing about race or skin color in that synopsis, and in fact such details are not an issue in the story, but it so happens that the hero is black, while the highborn lady whom he heroically rescues and whose love he wins is white. The heroine, the Lady Raire, is described near the beginning of the book; the hero, Billy Danger, is the first-person narrator:
The girl . . . I had to stop and get the other eyelid up. No girl could be that pretty. She had jet black hair and smoky gray eyes big enough to go wading in; an oval face, mellow ivory-colored skin, features like one of those old statues. She was wearing a white coverall, and the form it fit was enough to break your heart.
The hero's dark complexion could easily be missed by the careless reader. It is first hinted at about halfway through the story:
I looked up a local surgeon who examined my wounds and clucked and after a lot of lab studies and allergy tests, put me under an anesthetic and rebuilt my shoulder with metal and plastic to replace what was missing. When the synthetic skin had stitched itself in with the surrounding hide, he operated again, to straighten out my ribs. He wanted to reupholster the side of my neck and jaw next, but the synthetic hide was the same pale color as the locals; it wouldn't have improved my looks much. And by then, I was tired of the pain and boredom of plastic surgery. My arm worked all right now, and I could stand straight again instead of cradling my smashed side. And it was time to move on.
And only near the end of the book do we learn that he is black:
"Sir Revenat," someone started, and let it drop. I could almost hear his mind racing, looking for the right line to take. But nobody, even someone who had only talked to me for five minutes three years before, could pretend to have forgotten my face: black-skinned, scarred, one-eyed.
Here's how Billy Danger was pictured by cover artists Tom Kidd and Richard Martin.