Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-flies-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit-labs/react': patch
---

Fix type compatibility with Preact when adding children to wrapped components.
3 changes: 1 addition & 2 deletions examples/preact/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export function App() {
<>
<ElementA foo="foo" onAChanged={() => {}}>
This goes in default slot
{/* TODO(augustjk): Add this back with #4142 */}
{/* <div slot="stuff">This goes in stuff slot</div> */}
<div slot="stuff">This goes in stuff slot</div>
</ElementA>
<ElementEvents
foo="foo"
Expand Down
24 changes: 18 additions & 6 deletions packages/labs/react/src/create-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,27 @@ export type ReactWebComponent<
// lifecycle methods or allow user to explicitly provide props.
type ElementProps<I> = Partial<Omit<I, keyof HTMLElement>>;

// Acceptable props to the React component. Omit keyof E from HTMLAttributes to
// prefer provided event handler mapping over React's built-in event handler
// props.
// Child type compatible with both React and Preact. It's based on
// `React.ReactNode` but using `JSX.Element` allows`VNode` to be acceptable in
// Preact projects.
type Child =
| JSX.Element
| React.ReactPortal
| string
| number
| boolean
| undefined;

// Acceptable props to the React component.
type ComponentProps<I, E extends EventNames = {}> = Omit<
React.HTMLAttributes<I>,
keyof E
// Omit keyof E to prefer provided event handler mapping over React's
// built-in event handler props.
| keyof E
// Omit children to replace with our own that's compatible with Preact.
| 'children'
> &
ElementProps<I> &
EventListeners<E>;
EventListeners<E> & {children?: Child | Child[]} & ElementProps<I>;

/**
* Type used to cast an event name with an event type when providing the
Expand Down