Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 20, 2025

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:

  • Server renders with one ID (e.g., textarea-abc123)
  • Client hydrates with a different ID (e.g., textarea-def456)
  • Results in hydration mismatches and console errors

Solution

Implemented a post-build script that automatically transforms generated components to use framework-appropriate ID generation:

React Components

  • Before: const mId = props.id ?? \textarea-${uuid()}`;`
  • After: const mId = props.id ?? \textarea-${useId()}`;withimport { useId } from "react"`

Vue Components

  • Before: const mId = props.id ?? \textarea-${uuid()}`;`
  • After: const mId = props.id ?? \textarea-${useId()}`;withimport { useId } from "vue"`

Angular & Stencil

  • Continue using uuid() function (no native useId() support)
  • No breaking changes

Changes Made

  1. Post-build script (scripts/post-build/use-id.ts) that:

    • Scans React and Vue components for ID generation patterns
    • Adds appropriate useId imports
    • Replaces uuid() with useId() in template literals
  2. Updated 8 components in both React and Vue:

    • textarea, switch, select, radio, input, custom-select-list-item, custom-select, checkbox
  3. Comprehensive testing:

    • Unit tests verifying correct transformation
    • Verification script confirming implementation
    • Documentation with technical details

Benefits

  • SSR Compatibility: Consistent server/client IDs in React and Vue
  • Framework-Appropriate: Uses each framework's recommended approach
  • Backward Compatible: Angular and Stencil unchanged
  • Zero Breaking Changes: Existing APIs remain the same

Verification

Run the verification script to confirm proper integration:

npx tsx scripts/verify-use-id.ts

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.io
    • Triggering command: node 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.

@Copilot Copilot AI changed the title [WIP] use mitosis target to generate IDs for components Implement framework-specific useId for SSR-compatible component ID generation Aug 20, 2025
@Copilot Copilot AI requested a review from mfranzke August 20, 2025 20:33
Copilot finished work on behalf of mfranzke August 20, 2025 20:33
Copy link

changeset-bot bot commented Aug 26, 2025

⚠️ No Changeset found

Latest commit: e81e803

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added 📕documentation Improvements or additions to documentation 🏘components labels Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏘components 📕documentation Improvements or additions to documentation

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

use mitosis target to generate IDs for components

2 participants