[985] Restore unique_id filter and use instead of Drupal's clean_unique_id#1012
[985] Restore unique_id filter and use instead of Drupal's clean_unique_id#1012
Conversation
📝 WalkthroughWalkthroughA custom 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/uniqueId.js (1)
5-9:⚠️ Potential issue | 🟠 MajorAlign JS
unique_idoutput with Drupal sanitization behavior.On Line 6, the raw
valueis used as the ID prefix. Drupal’s server-side filter sanitizes first (Html::getId($id)), so Storybook can generate different/invalid IDs for the same input.Proposed fix
function uniqueId(twigInstance) { + const sanitizeId = input => + String(input ?? '') + .toLowerCase() + .trim() + .replace(/[\s_]+/g, '-') + .replace(/[^a-z0-9-]/g, '-') + .replace(/-+/g, '-') + .replace(/^-|-$/g, '') || 'id'; + // unique ID generator via https://stackoverflow.com/a/48593447 twigInstance.extendFilter( 'unique_id', value => - `${value}--${(Date.now() * 1000 + Math.random() * 1000) + `${sanitizeId(value)}--${(Date.now() * 1000 + Math.random() * 1000) .toString(16) .replace(/\./g, '') .padEnd(14, '0')}` ); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/uniqueId.js` around lines 5 - 9, The prefix `value` is used raw when building the ID, causing mismatch with Drupal's Html::getId sanitization; update the unique id generator in lib/uniqueId.js to sanitize the `value` the same way Drupal does before concatenating the timestamp suffix (e.g., normalize to ASCII, lowercase, replace non-alphanumeric characters with '-', collapse/trim leading/trailing '-' and ensure it doesn't start with a digit or empty — add a fallback prefix if needed), then use that sanitizedPrefix in place of `value` in the template string so Storybook IDs match Drupal-generated IDs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@lib/uniqueId.js`:
- Around line 5-9: The prefix `value` is used raw when building the ID, causing
mismatch with Drupal's Html::getId sanitization; update the unique id generator
in lib/uniqueId.js to sanitize the `value` the same way Drupal does before
concatenating the timestamp suffix (e.g., normalize to ASCII, lowercase, replace
non-alphanumeric characters with '-', collapse/trim leading/trailing '-' and
ensure it doesn't start with a digit or empty — add a fallback prefix if
needed), then use that sanitizedPrefix in place of `value` in the template
string so Storybook IDs match Drupal-generated IDs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1292c3c1-5d73-4418-aede-328f1e5c90e4
📒 Files selected for processing (11)
.storybook/preview.jsgesso_helper/gesso_helper.services.ymlgesso_helper/src/TwigExtension/UniqueIdTwigExtension.phplib/uniqueId.jssource/03-components/accordion/accordion-item.twigsource/03-components/overlay-menu/overlay-menu.twigsource/03-components/pager/pager--mini/pager--mini.twigsource/03-components/side-menu/side-menu.twigsource/03-components/tabs/tabs.twigtemplates/form/form.html.twigtemplates/layout/html.html.twig
Fixes #985