-
Notifications
You must be signed in to change notification settings - Fork 1
[CDX-458] Resolve incompatibility with react 1617 #48
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
Open
esezen
wants to merge
9
commits into
main
Choose a base branch
from
cdx-458-components-ui-resolve-incompatibility-with-react-1617-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
53e445d
Replace @radix-ui/react-slot with manual Slot implementation
Alexey-Pavlov 329e1a8
Add tests
esezen 2b9bf9a
Address comments
esezen 871ba47
React compatibility tests
esezen a6b4765
Reproduce previous error
esezen bd69be5
Address comments
esezen fa2b007
Use ci
esezen 7400545
Update all locks
esezen 538963f
Fail fast
esezen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| name: React compat matrix | ||
| on: | ||
| pull_request: | ||
| branches: | ||
| - "**" | ||
| concurrency: | ||
| group: react-compat-${{ github.head_ref }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| compat: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: true | ||
| matrix: | ||
| react-major: ["16", "17", "18", "19"] | ||
| steps: | ||
| - name: Check out code | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "22.18.0" | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| - name: Install library deps | ||
| run: npm ci | ||
| - name: Build library | ||
| run: npm run compile | ||
| - name: Pack library | ||
| shell: bash | ||
| run: | | ||
| npm pack --pack-destination . | ||
| tarballs=(constructor-io-constructorio-ui-components-*.tgz) | ||
| if [ ${#tarballs[@]} -ne 1 ]; then | ||
| echo "Expected exactly 1 tarball, found ${#tarballs[@]}: ${tarballs[*]}" >&2 | ||
| exit 1 | ||
| fi | ||
| mv "${tarballs[0]}" constructorio-ui-components.tgz | ||
| - name: Install fixture deps | ||
|
esezen marked this conversation as resolved.
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| working-directory: test/react-compat/${{ matrix.react-major }} | ||
| run: npm ci --no-audit --no-fund | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| - name: Typecheck fixture | ||
| working-directory: test/react-compat/${{ matrix.react-major }} | ||
| run: npm run typecheck | ||
| - name: Webpack build | ||
| working-directory: test/react-compat/${{ matrix.react-major }} | ||
| run: npm run build | ||
| - name: Run fixture tests | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| working-directory: test/react-compat/${{ matrix.react-major }} | ||
| run: npm test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| import React from 'react'; | ||
| import { render, cleanup, fireEvent } from '@testing-library/react'; | ||
| import { describe, test, expect, vi, afterEach } from 'vitest'; | ||
| import { Slot } from '@/utils'; | ||
|
|
||
| describe('Slot', () => { | ||
| afterEach(() => { | ||
| cleanup(); | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| // 1. Renders the single child element with no wrapper | ||
| test('renders the single child element with no extra wrapper DOM', () => { | ||
| const { container } = render( | ||
| <Slot> | ||
| <a href='/'>link</a> | ||
| </Slot>, | ||
| ); | ||
| expect(container.firstChild).not.toBeNull(); | ||
| expect((container.firstChild as HTMLElement).tagName).toBe('A'); | ||
| expect(container.firstChild?.parentElement).toBe(container); | ||
| }); | ||
|
|
||
| // 2. Forwards an object ref to the child DOM node | ||
| test('forwards an object ref to the child DOM node', () => { | ||
| const ref = React.createRef<HTMLAnchorElement>(); | ||
| render( | ||
| <Slot ref={ref as React.Ref<HTMLElement>}> | ||
| <a href='/'>link</a> | ||
| </Slot>, | ||
| ); | ||
| expect(ref.current).toBeInstanceOf(HTMLAnchorElement); | ||
| }); | ||
|
|
||
| // 3. Forwards a callback ref to the child DOM node | ||
| test('forwards a callback ref to the child DOM node', () => { | ||
| let received: HTMLElement | null = null; | ||
| render( | ||
| <Slot ref={(node) => { received = node; }}> | ||
| <a href='/'>link</a> | ||
| </Slot>, | ||
| ); | ||
| expect(received).toBeInstanceOf(HTMLAnchorElement); | ||
| }); | ||
|
|
||
| // 4. Composes slot's ref with child element's own ref | ||
| test('composes slot ref with child own ref so both resolve to the same DOM node', () => { | ||
| const slotRef = React.createRef<HTMLAnchorElement>(); | ||
| const childRef = React.createRef<HTMLAnchorElement>(); | ||
| render( | ||
| <Slot ref={slotRef as React.Ref<HTMLElement>}> | ||
| <a href='/' ref={childRef}> | ||
| link | ||
| </a> | ||
| </Slot>, | ||
| ); | ||
| expect(slotRef.current).toBeInstanceOf(HTMLAnchorElement); | ||
| expect(childRef.current).toBeInstanceOf(HTMLAnchorElement); | ||
| expect(slotRef.current).toBe(childRef.current); | ||
| }); | ||
|
|
||
| // 5. Concatenates className from slot and child | ||
| test('concatenates className from slot and child', () => { | ||
| const { container } = render( | ||
| <Slot className='slot-class'> | ||
| <a href='/' className='child-class'> | ||
| link | ||
| </a> | ||
| </Slot>, | ||
| ); | ||
| const el = container.firstChild as HTMLElement; | ||
| expect(el.className).toContain('slot-class'); | ||
| expect(el.className).toContain('child-class'); | ||
| }); | ||
|
|
||
| // 6. Shallow-merges style; child overrides slot on conflict | ||
| test('shallow-merges style with child winning on conflict', () => { | ||
| const { container } = render( | ||
| <Slot style={{ color: 'red', margin: '4px' }}> | ||
| <a href='/' style={{ color: 'blue', padding: '2px' }}> | ||
| link | ||
| </a> | ||
| </Slot>, | ||
| ); | ||
| const el = container.firstChild as HTMLElement; | ||
| expect(el.style.color).toBe('blue'); | ||
| expect(el.style.margin).toBe('4px'); | ||
| expect(el.style.padding).toBe('2px'); | ||
| }); | ||
|
|
||
| // 7. Composes event handlers: child runs first, then slot | ||
| test('composes event handlers: child handler runs before slot handler', () => { | ||
| const order: string[] = []; | ||
| const { container } = render( | ||
| <Slot onClick={() => { order.push('slot'); }}> | ||
| <button onClick={() => { order.push('child'); }} type='button'> | ||
| click me | ||
| </button> | ||
| </Slot>, | ||
| ); | ||
| const button = container.firstChild as HTMLButtonElement; | ||
| fireEvent.click(button); | ||
| expect(order).toEqual(['child', 'slot']); | ||
| }); | ||
|
|
||
| // 7b. Slot handler is skipped when child handler calls preventDefault | ||
| test('slot handler is skipped when child handler calls preventDefault', () => { | ||
| const slotClick = vi.fn(); | ||
| const { container } = render( | ||
| <Slot onClick={slotClick}> | ||
| <button onClick={(e) => e.preventDefault()} type='button'> | ||
| click me | ||
| </button> | ||
| </Slot>, | ||
| ); | ||
| const button = container.firstChild as HTMLButtonElement; | ||
| fireEvent.click(button); | ||
| expect(slotClick).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| // 8. Slot's handler fires when child has no handler of the same name | ||
| test("slot's handler fires when child has no handler for that event", () => { | ||
| const slotClick = vi.fn(); | ||
| const { container } = render( | ||
| <Slot onClick={slotClick}> | ||
| <button type='button'>click me</button> | ||
| </Slot>, | ||
| ); | ||
| const button = container.firstChild as HTMLButtonElement; | ||
| fireEvent.click(button); | ||
| expect(slotClick).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| // 9. Child non-handler prop wins over slot's | ||
| test('child non-handler props win over slot props', () => { | ||
| const { container } = render( | ||
| <Slot id='slot-id' aria-label='slot label'> | ||
| <a href='/' id='child-id' aria-label='child label'> | ||
| link | ||
| </a> | ||
| </Slot>, | ||
| ); | ||
| const el = container.firstChild as HTMLElement; | ||
| expect(el.id).toBe('child-id'); | ||
| expect(el.getAttribute('aria-label')).toBe('child label'); | ||
| }); | ||
|
|
||
| // 10. Throws when given multiple children | ||
| test('throws when given multiple children', () => { | ||
| vi.spyOn(console, 'error').mockImplementation(() => {}); | ||
| expect(() => | ||
| render( | ||
| <Slot> | ||
| <span>one</span> | ||
| <span>two</span> | ||
| </Slot>, | ||
| ), | ||
| ).toThrow(/React.Children.only/); | ||
| }); | ||
|
|
||
| // 11. Returns null when given no valid React element child | ||
| test('returns null when given a non-element child (plain string)', () => { | ||
| const { container } = render(<Slot>{'plain string'}</Slot>); | ||
| expect(container.firstChild).toBeNull(); | ||
| }); | ||
|
|
||
| // 12. Forwards ref correctly when child is a forwardRef component | ||
| test('forwards ref when child is a forwardRef component', () => { | ||
| const Inner = React.forwardRef<HTMLAnchorElement, React.ComponentProps<'a'>>((props, ref) => ( | ||
| <a ref={ref} {...props} /> | ||
| )); | ||
| Inner.displayName = 'Inner'; | ||
|
|
||
| const slotRef = React.createRef<HTMLAnchorElement>(); | ||
| render( | ||
| <Slot ref={slotRef as React.Ref<HTMLElement>}> | ||
| <Inner href='/x'>link</Inner> | ||
| </Slot>, | ||
| ); | ||
| expect(slotRef.current).toBeInstanceOf(HTMLAnchorElement); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Suggestion:
fail-fast: truemeans that if the React 16 cell fails, the React 17/18/19 cells are cancelled immediately. This is efficient for the CDX-458 use case (fail fast on the oldest version), but it makes it harder to see which versions are broken when multiple cells fail simultaneously (e.g. after a dependency upgrade). Consider settingfail-fast: falseso all four cells always run to completion and the full compatibility picture is visible in a single CI run.