Using matched UK administrative data, this paper examines how global trade expansion during 2002-2011 affected R&D investment of British firms. We find that Chinese import competition significantly discouraged firm R&D. Booming export demand, by contrast, stimulated their innovation efforts, mitigating the adverse competition effect. Our findings further reveal heterogeneity. More productive firms increased R&D spending by more in response to foreign demand. Exporting firms were less hurt by Chinese penetration than non-exporters. These together indicate the uneven consequences of globalization over the past decades for firm innovation, more detrimental to domestic and less profitable firms.