The problem
Consider a model that fetches a user’s name from an API inafterInit(). Before the fetch resolves, your HTML shows the default value you set in beforeInit() — something like --. That blank placeholder flickers into view and then snaps to the real value. Cloaking hides the element entirely until Sprincul is ready to show the correct state.
The solution: data-cloaked
Add the data-cloaked attribute to any element you want hidden during initialization. Sprincul removes the attribute when the appropriate initialization phase completes. You supply the CSS rule that does the hiding:
visibility: hidden, opacity: 0, or any other approach that suits your design.
Two scopes
Cloaking works at two levels, and they behave differently.Model-level cloaking
Adddata-cloaked to a data-model container. Sprincul removes the attribute after that model’s afterInit hook completes, including any async work inside it.
afterInit() is async and awaits a network request, the element stays hidden until the await resolves. This prevents users from seeing incomplete data during hydration.
Page-level cloaking
Adddata-cloaked to the <body> element. Sprincul removes the attribute after all models’ afterInit hooks are called — but does not wait for them to complete.
Choosing the right scope
Full HTML + CSS example
Cloaking in subsequent init() calls
If you call Sprincul.init() again to hydrate dynamically added model markup, cloaking works exactly the same way for newly added elements. Sprincul treats freshly added data-cloaked attributes on new model roots the same as it does on the first pass.
For more on calling
Sprincul.init() multiple times to handle dynamic content, see the Dynamic Content guide.