ux icon indicating copy to clipboard operation
ux copied to clipboard

[LiveComponent] Cannot assign null to property Symfony\UX\LiveComponent\Twig\TemplateMap::$map of type array

Open tijnema opened this issue 1 year ago • 17 comments

Hi,

During deployment on our live environment we quite often get the error Cannot assign null to property Symfony\UX\LiveComponent\Twig\TemplateMap::$map of type array

It seems to be related to a race condition with cache. Not sure how it occurs exactly, but it can easily be reproduced by deleting the live_components_twig_templates.map file from the cache folder.

tijnema avatar Jul 05 '24 08:07 tijnema

Do you sometimes prune / delete your cache folder ? Or even with a CachePoolClearer maybe ?

smnandre avatar Jul 05 '24 09:07 smnandre

We use Ansistrano for deployment. It places new version of the project in a new directory (with empty cache folder), and then switches a symlink to this new folder.

tijnema avatar Jul 05 '24 10:07 tijnema

Do you warm the cache before the symlink ? The other possibility would be: do you change your APP_SECRET between deployments ?

smnandre avatar Jul 05 '24 10:07 smnandre

APP_SECRET never changes. We currently do not warm the cache before symlink. That might just fix the issue. The issue does remain when clearing the cache on a running instance though. I guess this piece of code could be written to work without existing cache too?

tijnema avatar Jul 05 '24 10:07 tijnema

Well, yes and no :)

Yes it would work to "render" a component.

But if you clear the cache (without rebuilding it) while a user is browsing a page containing live components, that would break.

Maybe we should generate this file in the "build" directory and not the "cache" one ?

smnandre avatar Jul 05 '24 11:07 smnandre

Is there at least some workaround? It happens constantly in one app I create, only in the docker container, though.

RikudouSage avatar Aug 23 '24 16:08 RikudouSage

Hi @RikudouSage, do you have APP_SECRET env variable configured?

smnandre avatar Aug 23 '24 18:08 smnandre

@RikudouSage Maybe you should warm the cache before running the app ?

tijnema avatar Sep 02 '24 07:09 tijnema

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Mar 03 '25 12:03 carsonbot

We are still experiencing this issue with Symfony 7.3 and UX 2.23.0. We warm our cache before each deployment, and have APP_SECRET defined.

benr77 avatar Mar 12 '25 15:03 benr77

Same in here: Symfony 6.4, UX 2.24.0 on PHP 8.3. Problem appears only on production env. While development works just fine. Thanks for awesome work.

bartlomiej84 avatar Apr 10 '25 12:04 bartlomiej84

Hey guys, same question/hint than previously: did you change anything in the cache (clear it / no build it / ..?)

smnandre avatar Apr 10 '25 12:04 smnandre

Our APP_SECRET env var is defined in a .env file and NOT in the actual environment. But it is defined.

We also build the cache when starting the Docker image, moments before deployment, and then never touch the cache until this image is replaced completely by the subsequent deployment.

benr77 avatar Apr 10 '25 12:04 benr77

Could you try defining a (stable) secret for LiveComponent ?

symfony console debug:config live_component

smnandre avatar Apr 11 '25 02:04 smnandre

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Oct 12 '25 12:10 carsonbot

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

carsonbot avatar Oct 26 '25 12:10 carsonbot

bin/console debug:config live_component

Current configuration for extension with alias "live_component"
===============================================================

live_component:
    secret: '%env(APP_SECRET)%'

I am double-checking and in all cases our APP_SECRET environment variable is defined correctly

benr77 avatar Oct 26 '25 12:10 benr77