This method works perfectly and I successfully use it wherever you need a secure display of images, taking into account the security rules.
To show dynamic images, I have created a special route for this server action, with a parameter in which I pass the ID of the required image. All images are displayed correctly. But in a situation where I apply the route not on the content page, but on the layout, the browser console gives an error (the error does not affect the operation of the application, the route works correctly and returns the correct image):
I have some ideas about the cause of this error in the console. I think that the route starts loading faster than the client side server connect, which returns the image ID, loads. After the server connect on the client side is loaded, the route returns the correct image.
Although this does not affect the operation of the application, I wanted to know if there is anything I can do to prevent this error from appearing in the console?