userfrosting / UserFrosting

Modern PHP user login and management framework
https://www.userfrosting.com
Other
1.64k stars 366 forks source link

White page of death when switching language in the user setting page #1263

Closed ablears closed 1 month ago

ablears commented 1 month ago

Affected sprinkle or package

userfrosting/UserFrosting

UserFrosting or package Version

5.1.3

Debug Data

UserFrosting Environnement Information
======================================

 -------------------- --------------------------------------------------------
  Framework version    5.1.3
  OS Name              Linux
  Main Sprinkle        My Application
  Main Sprinkle Path   /var/www/portal-staging.internationalbarcodes.net/app/
  Environment mode     default
  PHP Version          8.3.10
  Node Version         v20.11.1
  NPM Version          10.5.0
 -------------------- --------------------------------------------------------

Loaded Sprinkles
================

 ------------------ --------------------------------------- ----------------------------------------------------------------------------------------------------
  Sprinkle           Namespace                               Path
 ------------------ --------------------------------------- ----------------------------------------------------------------------------------------------------
  Core Sprinkle      UserFrosting\Sprinkle\Core\Core         /var/www/portal-staging.internationalbarcodes.net/vendor/userfrosting/sprinkle-core/app/src/../
  Account Sprinkle   UserFrosting\Sprinkle\Account\Account   /var/www/portal-staging.internationalbarcodes.net/vendor/userfrosting/sprinkle-account/app/src/../
  AdminLTE Theme     UserFrosting\Theme\AdminLTE\AdminLTE    /var/www/portal-staging.internationalbarcodes.net/vendor/userfrosting/theme-adminlte/app/src/../
  Admin Sprinkle     UserFrosting\Sprinkle\Admin\Admin       /var/www/portal-staging.internationalbarcodes.net/vendor/userfrosting/sprinkle-admin/app/src/../
  My Application     UserFrosting\App\MyApp                  /var/www/portal-staging.internationalbarcodes.net/app/src/../
 ------------------ --------------------------------------- ----------------------------------------------------------------------------------------------------

Database config
===============

 ------------ ------------
  CONNECTION   mysql
 ------------ ------------
  DRIVER       mysql
  HOST         localhost
  PORT         3306
  DATABASE     portal
  USERNAME     *********
  PASSWORD     *********
 ------------ ------------

Testing database connection...
==============================

 [OK] Database connection successful

Chat Discussion (optional)

No response

Description

The site only shows in English.

Running php bakery locale:dictionary and selecting a language, eg pt_BR, brings back the full dictionary OK.

My sprinkle has the language files at /app/locale/pt_BR/*. Running cat messages.php shows my translations.

/app/config/default.php includes site.locales.available which contains pt_BR' => true

The HTML head tag contains the language code <html lang="pt_BR" style="height: auto; min-height: 100%;">

The only clue is the output of php bakery locale:compare -l en_US -r pt_BR which shows

=================
Comparing `en_US` with `pt_BR`
------------------------------
Comparison between Brazilian portuguese and English
---------------------------------------------------
In` ByteString.php line 444:
  Invalid "UTF-8" string.

Translations worked in 4 and 5, but not after upgrading to 5.1

So I added error logging just before the error message to identify the string: string(59) "�lido. Escolha um nome diferente, ou clique em 'sugestão'."

Searching for that string: ack 'Escolha um nome diferente' . app/sprinkles/sprinkle-account/app/locale/pt_BR/messages.php 144: 'NOT_AVAILABLE' => 'Usuário <strong>{{user_name}}</strong> não é válido. Escolha um nome diferente, ou clique em \'sugestão\'.',

So the error is coming from v**á**lido in the string above.

Running a similar comparison using a different language also results in errors, eg php bakery locale:compare -l en_US -r fr_FR shows an error for string(20) "� la page d'accueil."

I'm not sure if the ByteString error is the reason translations are not showing, but at least it's something to work off.

Logging in and changing my user profile language at /account/settings/profile to a non-English language results in a white screen with no errors in either the PHP or userfrosting log files.

Steps To Reproduce

No response

lcharette commented 1 month ago

I've been able to replicate the Invalid "UTF-8" string error in the bakery command, however the website works correctly when using the built in PHP server.

The white page you're seeing might not be related. Does it appear on every page? Have you checked the browser console for any error? Otherwise, can you double check the logs to get any clues ?

ablears commented 1 month ago

Hi, the white page appears on the /account/settings/profile route if I change my language and save the change. No PHP, userfrosting or console log errors. The env is set to debug.

https://somup.com/cZQIVtmyEL shows the issues.

To confirm:

  1. A fresh install exhibits the bakery command error.
  2. For non-logged in users, the pages are always in English regardless of the html lang attribute
  3. Logging in and setting a language at /account/settings/profile causes the white screen but the language does update. Viewing the pages then does show in the correct language.
lcharette commented 1 month ago

So looks like three issues... I wasn't able to replicate the white page again. Did you get the same error in a fresh install? Any custom code to the account/setting pages?

lcharette commented 1 month ago

I've split the issue in 3 since there's really 3 problem here. Let focus on the white page of death here. The other two issues I can replicate and should be able to fix relatively soon.

ablears commented 1 month ago

Hi, thanks for your help so far.

I did a code comparison between my template at /app/templates/pages/account-settings.html.twig and the one supplied in vendor/userfrosting/theme-adminlte/app/templates/pages/account-settings.html.twig. There were no differences, however deleting /app/templates/pages/account-settings.html.twig fixed the issue.

What I did notice is that when the error triggered (with my template in place), the URL would change to /account/settings/profile.

I've not zeroed in on the exact cause, but it appears to be related to my setup and I don't need to make changes to account-settings.html.twig, so I think we can close this one.

lcharette commented 1 month ago

Alright. Let me know if this needs to be reopened.