When showing posts from wordpress and presenting a date. I get the following warning the console: Warning: Text content did not match. Server: "January 20, 2021" Client: "20 januari 2021"
Im first using the code from the mars theme to get the date: const data = state.source.get(state.router.link); const post = state.source[data.type][data.id]; const date = new Date(post.date);
When presenting the date I want to adjust it to a Swedish format: date.toLocaleDateString("sv-SE", { month: "long", day: "numeric", year: "numeric" })
Are there server options I need to adjust, or why is frontity comparing server date with the client date?
That warning is returned by React because the HTML code returned by the server doesn’t match the one generated in the browser during hydration.
The problem, though, is related to the Node version you are using. Before Node 13.0, the toLocaleDateString() method doesn’t handle the locale argument ("sv-SE" in your code), it just ignore it. As stated in the MDN documentation for that method:
Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the function silently falls back to en-US .
You can just update the Node version to solve this. If you cannot update it, I guess you would have to use a different way to localize dates.