Velo code to render components conditionaly SSR

Hi i’m using some velo code to conditionnaly render different style components.

On initial load the page flickers with the wrong components when my conditions hit.

Is there anyway to move the code i have in the on.Ready to be processed on the server vs the client?

I’m using the .show() .hide() expande() collapse()

Here is the function i’m running in the onReady hook.

function isInStock () {
//console.log(wixWindow.rendering.env)
$w ( ‘#pageApp1’ ). getProduct ()
. then (( product ) => {
if ( product.price === 0 ) {
getImages ( product );
$w ( “#box1” ). expand ()
$w ( “#box1” ). show ()
$w ( “#pageApp1” ). collapse ()
$w ( “#pageApp1” ). hide ()
if ( product.additionalInfoSections.length > 0 ) {
$w ( “#box5” ). expand ()
$w ( “#box5” ). show ()
}
} else {
$w ( “#box1” ). hide ()
$w ( “#box1” ). collapse ();
$w ( “#pageApp1” ). expand ()
$w ( “#pageApp1” ). show ();
}
})
}

getProduct is for use in the frontend. Here are the backend API’s for reference

Is is possible to set everything to be hidden until this promise is resolved? So that nothing shows that shouldn’t?

Thats what i ended up doing. Thank you.

Set my main store app as hidden (not collapsed to avoid shifting around…) It would be nice to have access to some hook that lets the server handle this type of logic and serve the correct components right away and then cache it for future requests <3

My current implementation is most likely really bad for performance but necessary for our use case…

Oh well, one day…!

Any plans on getting something similar to the shopify storefront api live on wix?

I’m glad you were able to figure something out!

And as far as your question, can you be more specific about what you would want to see?

Oofta i could go on for a while,

I want to be able to build my own frontend in nextjs. A headless approach. I understand that it is already doable, but i would like to avoid the checkout, payment processing, shipping, discounts, taxes headache & utilise all the wonderful apis wix offer.

The nice thing with the storefront api, is that they handle the whole checkout process + shipping/taxes, leaving the frontend totally customizable, less bloaty :slight_smile:

https://dev.wix.com/api/rest/wix-stores/carts
If we could get a little create endpoint there, that could be nice :slight_smile:

Also if wix paper performance vs perceived performance (great on desktop), none of this would be necessary!

I’m sure a lot of things are in the works. Bottle in the sea.

Thank you for sharing and yes there are TONS of things in the works all the time. So much so that I can’t even really say one way or the other at the moment, but part of my job in devrel is to keep tabs on what our developers are doing/thinking about/wishing for so just taking a note for now so I can advocate :slight_smile: