Support for SSR. Current index.web.js is directly calling browser-only objects, which is not possible while being rendered on the server.
Because localize all the things everywhere!
I noticed the calls are to navigator
and window
objects. Those statements are called as soon as any code imports react-native-localize
, so it would be necessary to "delay" that to a later stage, or call them lazily or even conditionally. I don't know how this module's internals work... yet π
This is a conditional example that would render properly on SSR:
export let constants: LocalizationConstants = generateConstants(
(navigator && navigator.languages) || [],
);
window && window.addEventListener("languagechange", () => {
constants = generateConstants(navigator.languages);
handlers.forEach(handler => handler());
});
The only complication is how to make constants
somehow wait or be populated until the browser is ready without breaking anything. This could work:
/* Server Side would need to be populated some othery way... */
export let constants: LocalizationConstants; // Would be undefined until...
document && document.addEventListener("DOMContentLoaded", function(event) {
constants = navigator.languages; // We're in business
});
But I'm not sure if an undefined constants
would break something, and there would of course need to be a way to know from the client which locale to use. I'll get back if I come up with something.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too