Unable to override library auto-definition to add external CSS & JS

Created on 1 May 2023, over 1 year ago
Updated 20 June 2023, over 1 year ago

Problem/Motivation

SDC lets you alter the auto-generated Drupal library using libraryOverrides in the component definition file. It will then treat the paths for CSS and JS as relative to the component library folder, so it can be found later on. This process does not check if the provided URL is external or not. This leads to broken URLs in the front-end.

Temporary workaround

Manually define a library that contains this external JS/CSS, and add a dependency to it in your component instead.

Steps to reproduce

Add the following to your component definition:

libraryOverrides:
  js:
    https://drupal.org/fake-dependency/index.min.js: { }
  css:
    component:
      https://drupal.org/fake-dependency/styles.css: { }

Then render the component normally.

You will observe that the browser is trying to request: https://d10.ddev.site/en/admin/config/modules/contrib/cl_devel/components/component-details/https://drupal.org/fake-dependency/index.min.js

Proposed resolution

The code that builds the path relative to the component directory should check if the path is external or not, in both CSS and JS.

Remaining tasks

  • Write the fix.
  • Add an automated test for the fix.
๐Ÿ› Bug report
Status

Fixed

Version

10.1 โœจ

Component
Renderย  โ†’

Last updated about 8 hours ago

Created by

e0ipso Can Picafort

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024