Shader TexelSize not updating when new texture is assigned

Running into a weird issue where the _MainTex_TexelSize property in my shader is not updating when a new Texture is assigned using Material.mainTexture = texture;

Some ways I am able to refresh the property are (which don’t make much sense):

  1. Constantly refreshing the mainTexture property of the material in an update loop
void Update()
{
    Material.mainTexture = Material.mainTexture;
}
  1. Adding a button that refreshes the mainTexture property. Similar to the above.
  2. Recompiling the shader at runtime.

Performing one of the above will magically update the texel size property in the shader and it will perform as expected.

This is a URP Unlit shader. Unity version is 2022.3.9f1. But issue was also experienced with Unity 2021.