Why does react app has two local storages?
I have encountered a weird behavior of my React app. For some reason it has two local storages. One at app IP and another – at app domain. I suspect this is happening because I set the domain to be a subdomain pointing to a specific IP via the URL redirect record in DNS configuration. When I try to set a storage item with
localStorage.setItem('item', 'value'), app does not pick it up because (I am figuring this is the case) it uses second storage while browser is using first one by default. Another weird aspect of this is that when app does
window.history.pushState(null, 'title', '?name=val'), it has no effect whatsoever, while if I do the same from the browser console, it works fine – URL gets updated. Everything works fine on localhost – there is only one storage and
window.history does what it is supposed to.
How can I fix this? Probably some configuration of
npm start? I tried setting
start: "PORT=80 HOST=subdomain.domain.com react-scripts start" in
package.json, but app does not start it this case at all.
Any ideas are welcome. Thanks.
Source: JavaSript – Stack OverflowNovember 27, 2021