So I have tried server side rendering on plenty of different sites but it never seems to work. Even with the code straight from the examples, it never works. Whenever an example has ssr I always have to get rid of it in order for the stuff to load from the databases such as the product reviews example.
I tried it with the new warmupData() with no success. Below is simple code I was doing to just try and show some data but nothing ever shows and it causes my pages to not load.
#ssr #serversiderendering #notworking
import wixData from 'wix-data';
import wixWindow from 'wix-window';
import {local} from 'wix-storage';
let promise;
let dataResults;
// start performing a query as soon as possible during
// the first render cycle and store the returned promise
if(wixWindow.rendering.renderCycle === 1) {
promise = wixData.query("Business").find();
}
// this will run twice, once on the
// backend and once in the browser
$w.onReady( function () {
// if it's the first render cycle, set up what
// to do when the query promise resolves
if(wixWindow.rendering.renderCycle === 1) {
promise.then( (results) => {
// use the query results for page setup
$w("#repeater3").data = results.items;
// if the first cycle is happening on the backend
if(wixWindow.rendering.env === "backend") {
// return the items from the query results
// to be used later in the browser
return results.items;
}
// if the first cycle is happening in the browser, just
// store the items from the query results in a variable
dataResults = results.items;
} );
}
// if it's the second render cycle, get the items from the query
// results returned in the first cycle and store them in a variable
else {
dataResults = wixWindow.rendering.warmupData;
}
// regardles of cycle, if in the browser, do some stuff that can
// only be done in the browser, like using local storage
if(wixWindow.rendering.env === "browser") {
//$w("#repeater3").data = local.getItem("businesses");
}
// if it's the first cycle, return the promise
// that rendering rendering should wait for
// if there will be a second cycle, the value the promise
// resolves to will be retrieved using warmupData
if(wixWindow.rendering.renderCycle === 1) {
return promise;
}
} );