Problem/Motivation

In  #3510711: Links prop type is detected before Breadcrumb adapter, Liam wrote:

It converts Url objects into strings, but radix:dropdown-menu needs them to be Url objects. So, I want to understand what causes LinksPropType to be executed on these values.

Indeed, url sub-property in the items component prop are not defined as string but as object in radix:dropdown-menu

url:
  type: object
  properties:
    options:
      type: object
       ...

So, the items prop must not be processed as LinksPropType which is expecting a string for the url sub-property:

url:
  type: string
  format: iri-reference

It must be ignored.

Proposed resolution

Maybe there is something to do in the Drupal\ui_patterns\SchemaManager\CompatibilityChecker service where I see a missing check in object properties.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pdureau created an issue. See original summary.

liam morland’s picture

Thanks for creating this.

pdureau’s picture

Status: Active » Needs work
Parent issue: #3510711: Links prop type is detected before Breadcrumb adapter »

First proposal pushed. I twas a big work, bigger than expected, but a necessary work.

The main fix:

  1. Many tests were added to tests/fixtures/CompatibilityCheckerData.yml to cover the situations when we want to check the inner properties of a JSOn object, so for AttributesPropType and LinksPropType
  2. In src/SchemaManager/CompatibilityChecker.php, we are now looping on object properties (and patternProperties) and checking their compatibility.

However, something was still wrong, some tests (automated or manual) were still KO. Because the current logic of JSON schema resolving in ComponentPluginManager was done separately from the CompatibilityChecker, with only a specific "conciliation" check for the root of the prop schema.

We didn't notice that until now because the only cases with JSON schema references not in the root of the prop schema were... LinksPropType ;)

So, other fix:

  1. We moved the specific check from src/ComponentPluginManager to src/PropTypePluginManager
  2. This check is now run after ReferencesResolver::resolve() so we are testing id property instead of $ref
  3. We keep running ReferencesResolver::resolve() in ComponentPluginManager but we add a call from src/SchemaManager/CompatibilityChecker.php, before calling Canonicalizer::canonicalize() in order to be sure both schema are resolved, so comparable.
  4. We have updated ui_patterns.services.yml to tests/src/Unit/SchemaManager/CompatibilityCheckerTest.php to inject the ReferencesResolver to CompatibilityChecker
  5. A little change in Canonicalizer::canonicalize() because ReferencesResolver sometimes transform arrays in StdClass.
pdureau’s picture

Assigned: pdureau » Unassigned
Status: Needs work » Needs review

Liam, is this MR fixing your issue?

---

Mikael, Christian, let's talk before merging.

This is a big change, in a deep, tricky and strategic part of the module, so lets' be extra careful.

Let's also check the performance because the mechanisms altered are processing heavy. I don't believe the change will hut performance (I kind og hope they may improve it a bit), but let's also be careful there.

liam morland’s picture

Unfortunately, I am not able to reproduce the problem anymore. The site is in major development. I uninstalled ui_patterns and putting it back now doesn't cause the problem, presumably due to other changes in the site.

pdureau’s picture

I am not able to reproduce the problem anymore. The site is in major development.

Don't worry, your input was very useful to identify an issue which have been hidden for one full year. Thanks a lot.

liam morland’s picture

Thanks. I encountered what is likely a related problem. Some block titles are being replaced with "1" (which suggest to me casting a Boolean to a string). If I uninstall ui_patterns, it no longer happens. The merge request does not fix the problem.

pdureau’s picture

Can you tell me more? What is the component prop definition?

liam morland’s picture

In our theme, we call SDC radix:block. At this point, the block label is correct. In the radix:block Twig file, the label has become "1". This is the label prop definition:

label:
type: ['string', 'null', 'boolean']
title: Label
description: The configured label of the block if visible.

In the preprocess for our SDC, the label is a string.

I wonder if it is converting the string to Boolean, which would be true, and that gets output as "1".

pdureau’s picture

This prop schema:

label:
  type: ['string', 'null', 'boolean']

Can be caught by:

Both plugins have the same priority level ("1") so the alphabetical order is ruling the discovery and this prop is managed by BooleanPropType.

My guts feeling is to ask: why ['string', 'null', 'boolean']? I struggle to understand what this schema is trying to achieve here, because the prop is only used in:

{% include 'radix:heading' with {
  content: label,
  ...
} %}

And heading's content prop has type: string schema. So, it may look like somehtign related to component authoring.

But our philosophy in UI Patterns is to adapt our logic to component implementations found in the wild, instead of dictating component authoring. We will not ask you to change the definition to fit with better with our module. So, maybe playing with priority order, to be sure the prop is maanged by StringPropType plugin, can be evaluated.

just_like_good_vibes’s picture

Hello, can someone review the work please :) ?

pdureau’s picture

Rebased.

As said before, this is a big change, in a deep, tricky and strategic part of the module, so lets' be extra careful.

Let's also check the performance because the mechanisms altered are processing heavy. I don't believe the change will hurt performance (I kind of hope it may improve it a bit), but let's also be careful there.

liam morland’s picture

This fixes the breadcrumbs for me. It does not fix the block titles, which still appear as "1".

liam morland’s picture

Current state of merge request.

pdureau’s picture

Status: Needs review » Reviewed & tested by the community

This fixes the breadcrumbs for me. It does not fix the block titles, which still appear as "1".

The MR is addressing the links issue and it is fortunate (but not that surprising) it also fixes #3510711: Links prop type is detected before Breadcrumb adapter.

liam morland’s picture

Status: Reviewed & tested by the community » Needs review

I added a change which fixes the block titles appearing as "1". This is done by increasing the priority of StringPropType.

liam morland’s picture

Category: Task » Bug report
StatusFileSize
new14.02 KB

Current state of merge request.

just_like_good_vibes’s picture

Assigned: Unassigned » just_like_good_vibes

hello guys, i added a small fix to make the MR be green.

just_like_good_vibes’s picture

i just added some little more code and more tests. i fixed the todo about additionalProperties.

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.