Issue
When deploying Client Extensions (CX) to a Liferay PaaS environment with multiple virtual instances, the CSS and JavaScript files for extensions on non-primary instances fail to load. This results in unstyled components and 404 errors in the browser console for these resources.
Symptoms may also include:
- Client Extensions appearing duplicated or with old modification dates in the Control Panel for non-primary instances.
- Themes on non-primary instances failing to load custom fonts or images.
- This issue is particularly common after attempting to use the dedicated Client Extensions pipeline, which is limited to the primary virtual instance.
Environment
- Liferay PaaS
- Liferay DXP Quarterly Releases
- CX deployed in multiple instances.
Resolution
The issue is typically caused by incorrect deployment methods leaving residual data in the database, combined with improper configuration for targeting multiple virtual instances. The dedicated Client Extensions pipeline should not be used in ths case, and the standard pipeline must be used.
Follow these steps to resolve the issue:
1. Clean Up Old Configurations from the Database
Previous deployment attempts (and if you don't have LPD-61895 in your patch level/hotfix(*)) can leave corrupt/dirty entries in the Configuration_ table. These must be removed. Connect to your PaaS instance's database with write privileges, and execute the following queries to clear all Client Extension configurations.
Warning: This is a destructive action. Ensure you have a database backup.
DELETE FROM Configuration_ WHERE configurationId LIKE '%CETConfiguration%';
DELETE FROM Configuration_ WHERE configurationId LIKE '%OAuth2ProviderApplicationHeadlessServerConfiguration%';
DELETE FROM Configuration_ WHERE configurationId LIKE '%org_apache_felix_cm_impl_DynamicBindings%';
1.1. (*) Avoid persisting CX configurations in the Database.
- Ask support to provide you with a hotfix including the fix LPD-61895. which will avoid persisting CX configurations in the
configuration_table and hence you will not incur in corrupt and mixed configurations for your CX.
2. Structure the Client Extensions Workspace
Organize your client-extensions workspace directory with subfolders named after the exact webId of each virtual instance. For example:
client-extensions/
├── intanceone.com/
│ ├── CX1/
│ │ └── client-extension.yaml
├── instancetwo.com/
│ ├── CX2/
│ │ └── client-extension.yaml
│ └── CX3/
│ └── client-extension.yaml
└── build.gradle
3. Configure the Gradle Build Script
Create a build.gradle file in the root of your client-extensions/ directory. This script automatically assigns each CX to the correct virtual instance based on its parent folder's name.
subprojects {
def projectDirName = parent.projectDir.name
println "Configuring tasks for subproject: $project.name. Directory name is: $projectDirName"
def createClientExtensionConfigTasks = getTasksByName("createClientExtensionConfig", true)
createClientExtensionConfigTasks.each{
it.setVirtualInstanceId(projectDirName)
}
def buildClientExtensionZipTasks = getTasksByName("buildClientExtensionZip", true)
buildClientExtensionZipTasks.each{
it.setArchiveBaseName("${project.name}_${projectDirName}")
}
}
Important: With this script in place, you must remove the dxp.lxc.liferay.com.virtualInstanceId property from all client-extension.yaml files, as the script handles this association. This property should never be used for CX in PaaS (only in a few specific and recommended occasions)
4. Update Resource Paths in Themes
The Gradle script modifies the bundle name of the Client Extension by appending the virtual instance ID (e.g., my-theme becomes my-theme_instance-two.com). Consequently, any hardcoded paths within your theme's CSS (e.g., for fonts, images or other resources) must be updated.
-
Old Path:
/o/my-theme-css/fonts/my-font.woff -
New Path:
/o/my-theme-css_instance-two.com/fonts/my-font.woff
5. Verify Custom Element Configuration
If a custom element's CSS is not loading, ensure its client-extension.yaml file does not reference non-existent stylesheets. If the styles are meant to come from a theme, remove the cssURLs property from the custom element's YAML file.
After completing all steps, perform a new build and deploy the services.