Problem/Motivation
On install of the module
line 19:
$output = \Drupal::service('renderer')->render($link);
Render context is empty, because render() was called outside of a renderRoot() or renderInIsolation()
LogicException: Render context is empty, because render() was called [error]
outside of a renderRoot() or renderInIsolation() call. Use
renderInIsolation()/renderRoot() or #lazy_builder/#pre_render instead. in
drupal-10.4.x/html/core/lib/Drupal/Core/Render/Renderer.php:303
Stack trace:
#0
drupal-10.4.x/html/core/lib/Drupal/Core/Render/Renderer.php(248):
Drupal\Core\Render\Renderer->doRender()
#1
drupal-10.4.x/html/modules/contrib/vrssfa/vrssfa.install(19):
Drupal\Core\Render\Renderer->render()
#2 [internal function]: vrssfa_install()
#3
drupal-10.4.x/html/core/lib/Drupal/Core/Extension/ModuleHandler.php(407):
call_user_func_array()
#4
drupal-10.4.x/html/modules/contrib/hux/src/HuxModuleHandler.php(70):
Drupal\Core\Extension\ModuleHandler->invoke()
#5
drupal-10.4.x/html/modules/contrib/hux/src/HuxModuleHandler.php(86):
Drupal\hux\HuxModuleHandler->Drupal\hux\{closure}()
#6
drupal-10.4.x/html/core/lib/Drupal/Core/Extension/ModuleInstaller.php(361):
Drupal\hux\HuxModuleHandler->invoke()
#7
drupal-10.4.x/html/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83):
Drupal\Core\Extension\ModuleInstaller->install()
#8
/usr/local/share/drush/commands/core/drupal/environment_common.inc(96):
Drupal\Core\ProxyClass\Extension\ModuleInstaller->install()
#9
/usr/local/share/drush/commands/core/drupal/environment_common.inc(163):
drush_module_install()
#10 /usr/local/share/drush/commands/pm/pm.drush.inc(1198):
drush_module_enable()
#11 /usr/local/share/drush/includes/command.inc(422): drush_pm_enable()
#12 /usr/local/share/drush/includes/command.inc(231):
_drush_invoke_hooks()
#13 /usr/local/share/drush/includes/command.inc(199): drush_command()
#14 /usr/local/share/drush/lib/Drush/Boot/BaseBoot.php(67):
drush_dispatch()
#15 /usr/local/share/drush/includes/preflight.inc(67):
Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#16 /usr/local/share/drush/drush.php(12): drush_main()
#17 {main}
Steps to reproduce
Proposed resolution
This error occurs because you're trying to use the renderer service during module installation, which is not allowed in Drupal. During the installation phase, the full render system is not yet available.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | fix_render_context_is_empty.patch | 652 bytes | avattikonda |
Comments
Comment #2
ramu_bharu commentedHello,
I tested the installation of the vrssfa module and did not encounter any errors or warnings. Could you please provide additional details or steps to help reproduce the issue?
Thanks,
Ramu
Comment #3
avattikonda@ramu_bharu
I tested the installation of the vrssfa module and did encounter above errors or warnings.
Below are the steps I followed to replicate
I attempted to enable the vrssfa module after downloading it via Composer and performing a fresh installation of Drupal 10.4. However, when I run drush en vrssfa, I encounter the following error:
In Renderer.php line 303:
Render context is empty, because render() was called outside of a renderRoot() or renderInIsolation() call. Use renderInIsolation()/renderRoot() or #lazy_builder/#pre_render instead.
I had attached a patch version which will fix the above error
Here I used renderInIsolation(): which safely renders the output outside of a regular render context, which is necessary when we're rendering something outside the normal page build process (like in an install hook).
Comment #4
socialnicheguru commentedComment #5
ramu_bharu commented