Wix Code changes revert after a few seconds on page load

I launched https://www.campdiabetes.com about a month ago. All code was working fine at launch.

Currently when the home page is loaded, under the ‘Upcoming Camps’ section there is a repeater that fills with each camps details. I use some code to present the date in the format I would like, when the page loads the dates are shown correctly however after a few seconds they revert to the placeholder text used in the Wix editor.

import wixData from 'wix-data';

$w.onReady(function () {
 $w("#campDataset").onReady(() => {
  $w("#repeater1").forEachItem(($w, itemData, index) => {
   
   const date = itemData.start;
   $w("#dateDayNum").text = date.toLocaleDateString("en-US", {day: "numeric"});
   $w("#dateDay").text = date.toLocaleDateString("en-US", {weekday: "short"});
   $w("#dateMonth").text = date.toLocaleDateString("en-US", {month: "short"});
  });
 });
});

View the following screencast to see the issue: 2018-09-09_1316
It’s important to note this was working fine at launch and has broken since then for some reason. There have not been any code changes until today when I discovered the issue and tried to republish the site to resolve the issue.

This issue does not occur in preview mode in the editor.
The issue is happening on Safari and Chrome and I have tried in private browser modes, where it also occurs.

The following errors are thrown to the console on page load;


The second error looks like it may be related, however formating is fine on page load, and then reverts?!?!

Any help or pointers would be very appreciated.

Jamie, it´s a guess, but what COULD be happening here is this:

  • you did not specify any rendering environment. Thus, page is first rendered at server. Since the new rendering engine (a couple of months back), the server takes it´s own locale settings (which might be US) and ignores yours
  • then the page is rendered again in the browser, doing the toLocaleDateString-stuff. But that uses a reserved keyword “date”.

Again, it´s a guess, but I would try this: change the “const date” into “let myDate” and change this also further down.
Then, wrap it into an if wixWindow.rendering.env = “browser” (see wix window doc)

Good luck.

1 Like

ps are you sure itemdata.start has a value? Try console.log it first.

Hello Giri, Thanks for your reply.

Thanks for brining wix-window to my attention. I’ve had a look at this and tried both your suggestion of scoping this to the browser env and also looked into the renderCycle, think that perhaps the secondary cycle was blasting my changes away. Both have made no difference;

import wixWindow from 'wix-window';

$w.onReady(function () {
 if(wixWindow.rendering.renderCycle === 2) {
 //if (wixWindow.rendering.env === "browser") {
  $w("#campDataset").onReady(() => {
   $w("#repeater1").forEachItem(($w, itemData, index) => {

   let myDate = itemData.start;

   // Console Log for Debugging
   console.log("rendering env: " + wixWindow.rendering.env) + " (backend | browser)";
   console.log("rendering cycle: " + wixWindow.rendering.renderCycle + " (1: first time server or client | 2: second time client | NaN after running on client)");
   console.log("myDate value: " + myDate);

   $w("#dateDayNum").text = myDate.toLocaleDateString("en-US", {day: "numeric"});
   $w("#dateDay").text = myDate.toLocaleDateString("en-US", {weekday: "short"});
   $w("#dateMonth").text = myDate.toLocaleDateString("en-US", {month: "short"});
   });
  });
 }
});


Testing env as “backend” or renderCycle as 1 or testing against isNaN() yields no results at all.

I’m completely stumped here and am unsure what’s happening. Does this appear to be a Wix bug?

I’ve requested support from Wix, however they have left me high and dry, stating that although they support Wix Code “features” they don’t support code written in wix code… I find this hard to grok considering what is the point of wix code, other than to develop custom code.

They have suggest if I believe this to be a bug that I need to fill in a “feedback form”… Starting to feel frustrated at the run around Wix support give me, it’s like trying to deal with a government department!

Any help from anyone here would be very much appreciated as Wix are obviously not going to support me.

Incase it helps, here is the console output from chrome (live site)

I have narrowed this down to the use of toLocaleDateString( ). If I replace the use of the global function with hard coded values the values do not disappear.

I’m using this exact code on another page and the error is not thrown.

I’m thinking that on the home page, for some reason the code is being executed twice first backend then in the browser, when it is executed in the browser env toLocaleDateString( ) is not accessible in this scope?

I have tried wixWindow.rendering.renderCycle === 1 and this didn’t seem to make a diffrence.

Would appreciate any feedback if anyone who as an idea or has seen similar behaviour?

Hi, Jamie.
It’s a bug, which will be fixed, but as a temporary workaround I may suggest you to initialize new date object from a value

let myDate = new Date(itemData.start);

Thank you!

1 Like

Thank you Ihor, this suggestion has resolved the bug on-page. Cheers, Jamie

1 Like

when is this going to be fixed ?

@mikemoynihan99 We’re working on a solution, I’ll let you know as soon as we release a fix for it.

Mike, Jamie, the issue is fixed.
Thank you for patience.

Thanks Ihor

Hi im having this exact same problem but with a rating display in my repeater,

here is the screencast vid:

https://www.screencast.com/t/jOUtJ5Jt

1 Like

I have the same issue, I have this code in the “Site” code which is shared to all pages.
$w.onReady(() => {
console.log(“2222222”, user);
}
from some reason it runs twice.
the solution with wixWindow is not working, I received twice “browser” … the counter is obsolete…
I really dont understand this Wix Bug.
Do you have any workaround? this function insert 2 records no matter how I try to block it,

Thanks!

See the article Corvid: About the Page Rendering Process .

@yisrael-wix I already found and tried using this article. I added a console.log for the enviroment field, it appears twice as “browser”! So its still runs twice include this hack mentioned in the article .

Hello
I added the following code:
$w.onReady(() => {
console.log(wixWindow.rendering.env);
console.log(wixWindow.rendering.renderCycle);
});
As you can see in the attached image, it happens twice no matter what.

Also according some place I ready the "renderCycle " is obsolete!
Why do I get “browser” twice??
How can it be resolved that the action will happen only once??

Thanks!

1 Like

@yisrael-wix Does this article explain why a date would load short format date, time and then switch to long format? I don’t have any code relate to dates in my code. Thx!

@yisrael-wix Loads like this


Then within seconds switches to this: