Project

General

Profile

Actions

Bug #10003

closed

WTimeEdit with WQApplication throws JavaScript error on refresh (with Wt 4.6.1)

Added by Chris Sykes over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
High
Assignee:
Target version:
Start date:
03/24/2022
Due date:
% Done:

100%

Estimated time:

Description

This was raised in the Help forum by a colleague, but it feels like a bug.

We are upgrading from Wt 4.5.0 to 4.6.1, and since the upgrade, we see the following JS error:

Uncaught TypeError: Cannot read properties of undefined (reading 'setLocale')
settings?wtd=h91zWlSU7eto6jQq&sid=876614815&webGL=true&scrW=1920&scrH=975&tz=0&tzS=Europe%2FLondon&htmlHistory=true&deployPath=%2F&request=script&rand=1076529179:234 Uncaught TypeError: Cannot read properties of undefined (reading 'setLocale')
    at eval (eval at Ea (settings?wtd=h91zWlSU7eto6jQq&sid=876614815&webGL=true&scrW=1920&scrH=975&tz=0&tzS=Europe%2FLondon&htmlHistory=true&deployPath=%2F&request=script&rand=1076529179:233:285), <anonymous>:19:28)
    at eval (eval at Ea (settings?wtd=h91zWlSU7eto6jQq&sid=876614815&webGL=true&scrW=1920&scrH=975&tz=0&tzS=Europe%2FLondon&htmlHistory=true&deployPath=%2F&request=script&rand=1076529179:233:285), <anonymous>:48:4)
    at eval (<anonymous>)
    at Ea (settings?wtd=h91zWlSU7eto6jQq&sid=876614815&webGL=true&scrW=1920&scrH=975&tz=0&tzS=Europe%2FLondon&htmlHistory=true&deployPath=%2F&request=script&rand=1076529179:233:285)
    at O (settings?wtd=h91zWlSU7eto6jQq&sid=876614815&webGL=true&scrW=1920&scrH=975&tz=0&tzS=Europe%2FLondon&htmlHistory=true&deployPath=%2F&request=script&rand=1076529179:234:87)
    at u (settings?wtd=h91zWlSU7eto6jQq&sid=876614815&webGL=true&scrW=1920&scrH=975&tz=0&tzS=Europe%2FLondon&htmlHistory=true&deployPath=%2F&request=script&rand=1076529179:165:160)
    at XMLHttpRequest.v (settings?wtd=h91zWlSU7eto6jQq&sid=876614815&webGL=true&scrW=1920&scrH=975&tz=0&tzS=Europe%2FLondon&htmlHistory=true&deployPath=%2F&request=script&rand=1076529179:165:354)

As indicated above, in our the error is triggered by a call to setlocale(...), but it
appears that any call to WApplication::refresh() will trigger a similar error.

My colleague prepared the following minimal app that reproduces the error:

#include <QCoreApplication>
#include "wtqt/WQApplication.h"
#include <Wt/WTimeEdit.h>

class MyApplication : public Wt::WQApplication
{
public:
    MyApplication(const Wt::WEnvironment &env);
    ~MyApplication();

    virtual void create();
    virtual void destroy();
};

MyApplication::MyApplication(const Wt::WEnvironment &env)
    : Wt::WQApplication(env, true)
{
}

MyApplication::~MyApplication()
{
}

void MyApplication::create()
{
    root()->addNew<Wt::WTimeEdit>();
    refresh();
}

void MyApplication::destroy()
{
}

Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
    return new MyApplication(env);
}

int main(int argc, char **argv)
{
    QCoreApplication a(argc, argv);

    return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
      return std::make_unique<MyApplication>(env);
    });
}

The JS error does not occur if a WApplication is used instead of a WQApplication.

It feels very similar to an error I raised against Wt 3.3.x a few years ago (since fixed): https://redmine.webtoolkit.eu/boards/2/topics/11782?r=11860#message-11860

This is currently blocking our upgrade to a more recent Wt release.

Let me know if you need any additional information.

Thanks,

Chris.

Actions #1

Updated by Korneel Dumon over 2 years ago

  • Status changed from New to InProgress
  • Assignee set to Korneel Dumon
  • Target version set to 4.8.0
Actions #2

Updated by Korneel Dumon over 2 years ago

Hi,

I can reproduce the issue. It also occurs with a regular WApplication for me, of course then you have to call create() from the constructor.

The thing than causes the error seems to be the call to refresh(). Why do you call it on construction? It's typically called when you change the locale of the application and want all WStrings to rerender. So I don't see a reason to call it when the application is first created.

Aside from that, it would of course be better if there is no error, so I'll still try to fix it.

Actions #3

Updated by Chris Sykes over 2 years ago

Korneel Dumon wrote in #note-2:

Why do you call it on construction?

We don't call it directly. I believe it's part of the Wt call-chain when we set the application timezone / locale.

Actions #4

Updated by Korneel Dumon over 2 years ago

  • Status changed from InProgress to Review

You're right, that's a perfectly reasonable use of setLocale(). The problem only occurs if there is a WSpinBox (which is used by WTimeEdit) in the app. If it's possible, I would suggest moving your call to setLocale up in the constructor code to before any WSpinBox is added to the widget tree. That should work as a workaround.

Actions #5

Updated by Chris Sykes over 2 years ago

Thanks for the suggestion of a work-around, but I don't think it'll work for us.

The interface time-zone is a user adjustable setting in our application.
It sounds like we're still going to hit this error whenever a user changes that setting.

I see the target release for this is currently 4.8.0, I'd be very interested in testing a patch against 4.6/4.7, once a fix is identified.

Actions #6

Updated by Roel Standaert over 2 years ago

  • Assignee changed from Korneel Dumon to Roel Standaert
Actions #7

Updated by Roel Standaert over 2 years ago

  • Status changed from Review to Implemented @Emweb
  • Assignee changed from Roel Standaert to Korneel Dumon
  • Target version changed from 4.8.0 to 4.7.2
  • % Done changed from 0 to 100

This has been fixed in the meantime. I'm hoisting this to Wt 4.7.2.

Actions #8

Updated by Roel Standaert over 2 years ago

  • Status changed from Implemented @Emweb to Resolved
Actions #9

Updated by Roel Standaert over 2 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF