[RFC] paraglide js prototyping outcome #1378
Replies: 2 comments 11 replies
-
@dominikg do you have an idea on how to remove the hydration flickering? |
Beta Was this translation helpful? Give feedback.
1 reply
-
CSR routing can be unexpected as messages are rendered after the initial load Run 1 is simulating slow 3G CleanShot.2023-09-19.at.22.22.15.mp4 |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Outcome
📺 5 min explanation video
Context
i18n libraries are complicated due to a) only send messages to the user that are rendered and b) making lazy loading of messages work with SSR.
The SvelteKit SDK (now renamed to paraglide JS) leveraged complicated AST transforms to achieve a and b, which led to complexity on the library side. Other i18n libraries push complexity to the user scope with namespaces or other manual tricks. Both AST transforms and manual interventions can't be the solution. Namespaces, for example, require coordination between developers, translators, designers, etc. A substantial operating complexity.
Long story short, we re-evaluated our and other i18n approaches and came up with an 80 line code runtime implementation, which seems to solve a and b with unprecedented simplicity.
Architecture
1. The messages are compiled to JS
Paraglide is embedded in the build step and compiles messages into JS. Having the messages in JS enables dynamic imports, provides type safety out the box (and also leads performance gains because no runtime interpolation logic is required but that is negalactable).
2. The lookup function lazy imports messages as required
The breakthrough comes from treating the lookup function
m
as synchronous function which itself listens to resolved imports. Upon resolved imports, the function triggers a re-render.3. (SSR pre-imports all messages)
The lookup function
m
is synchronous, if messages have been imported. Thus, SSR works out of the box by importing all messages on the server where size has no impact anyway.Code
The
paraglide-prototyping
contains multiple prototypes. The here presented prototype is the sveltekit-function one.Open questions
1. How to avoid hydration flickering?
See minute 3:10
Beta Was this translation helpful? Give feedback.
All reactions