Nationalism is a domestic reaction to foreign invasion (be it militarily or by mass immigration) and the consequential displacement of the local population - real or perceived.
Foreigners visiting are guests and are welcome. But foreigners arriving as permanent settlers threaten to compete with the territory and rights of the local ancestral population - again, real or perceived. So any immigration program warrants prior approval by the local population, and sensitive and respectful settling, adjustment, communication and time and space for assimilation to integrate.
Humans are territorial by nature. Foreigners visiting are guests and are welcome. But foreigners arriving as permanent settlers can threaten to be competition with the local population - again, real or perceived. So the immigration process demands local acceptance and careful and respectful settling, adjustment, communication and time and space for foreigner assimilation with the local ancestral population.
History has shown that over time, foreigners can become accepted by the local population if assimilation is carefully managed in small doses over time. The rate needs to be evolutionary not revolutionary.
Britain's foreign invasion of Australia never respected or tried to assimilate with the local Aboriginal peoples. It is a lesson of history still not learnt in Australia.