-
Notifications
You must be signed in to change notification settings - Fork 13
Implement framework-specific useId for SSR-compatible component ID generation #4797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: mfranzke <787658+mfranzke@users.noreply.github.com>
Co-authored-by: mfranzke <787658+mfranzke@users.noreply.github.com>
|
| if (!content.includes('useId') && !content.includes('import { useId }')) { | ||
| console.log('Adding useId import'); | ||
| content = content.replace( | ||
| /import \* as React from "react";/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very specific. What if the import is like
import React from 'react';
or
import * as React from 'react';
the replacement would not work. Do we have to consider this?
|
|
||
| // Check if file uses uuid for ID generation | ||
| if (content.includes('uuid()') && content.includes('-${uuid()}')) { | ||
| console.log(`Processing file: ${filePath}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For debugging, the detailed console.log is great, but it might inflate the CI logs. We should check, if we need all log output.
|
A changeset is missing. |
This PR implements framework-specific ID generation using native
useId()hooks for React and Vue components to resolve SSR hydration mismatches while maintaining backward compatibility for Angular and Stencil.Problem
Components that generate unique IDs (form components like textarea, input, select, etc.) were using a custom
uuid()function across all frameworks. This caused SSR hydration issues because:textarea-abc123)textarea-def456)Solution
Implemented a post-build script that automatically transforms generated components to use framework-appropriate ID generation:
React Components
const mId = props.id ?? \textarea-${uuid()}`;`const mId = props.id ?? \textarea-${useId()}`;withimport { useId } from "react"`Vue Components
const mId = props.id ?? \textarea-${uuid()}`;`const mId = props.id ?? \textarea-${useId()}`;withimport { useId } from "vue"`Angular & Stencil
uuid()function (no nativeuseId()support)Changes Made
Post-build script (
scripts/post-build/use-id.ts) that:useIdimportsuuid()withuseId()in template literalsUpdated 8 components in both React and Vue:
Comprehensive testing:
Benefits
Verification
Run the verification script to confirm proper integration:
This addresses the SSR hydration issue by leveraging framework-native solutions while maintaining compatibility across all supported targets.
Fixes #3419 & #2395
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
googlechromelabs.github.ionode install.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
🔭🐙🐈 Test this branch here: https://design-system.deutschebahn.com/core-web/review/copilot/fix-3419