Not sure racism is the appropriate word more xenophobia than anything. It a little disingenuous to say it was racially motivated, albeit that undoubtedly there were a number who voted leave for that reason.
The driving factor was almost certainly the detach between politicians and large swathes of the general public who believed that they were forgotten about. Geographically the areas that voted leave were those that were most affected by the loss of heavy industries followed by years of no investment other than low income jobs provided by call centres and distribution warehouses, the majority of which appeared to be “Funded by the EU”, hence leading to a general distrust of the EU.
Many saw the vote as a way to get some change, however as with most things the uninformed shout, or in this case vote first and then ask questions later when it’s all too late.
Whilst clearly the wrong choice and it being inevitably painful to the UK. On its own we might have managed with just Brexit. Compound by the other crises of Covid and now war in Ukraine, it’s going to be many years before we recover, if at all.