-
Couldn't load subscription status.
- 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 <[email protected]>
Co-authored-by: mfranzke <[email protected]>
|
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