Skip to content
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

[DRAFT] refactor: drop lit/react in favor of React built-in support #286

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion dev/kitchen-sink/Row1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function Row1() {
<div>Accordion content 2</div>
</AccordionPanel>
</Accordion>
<AvatarGroup prefix="Users: " items={[{ name: 'Jane Roe', abbr: 'JD' }]}></AvatarGroup>
<AvatarGroup items={[{ name: 'Jane Roe', abbr: 'JD' }]}></AvatarGroup>
<Chart title="Chart" style={{ height: '300px' }}>
<ChartSeries title="Items" type="bar" values={[10, 20, 30]}></ChartSeries>
</Chart>
Expand Down
82 changes: 28 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@types/karma-chrome-launcher": "^3.1.4",
"@types/karma-mocha": "^1.3.4",
"@types/mocha": "^10.0.10",
"@types/react-dom": "^18.3.3",
"@types/react-dom": "^19",
"@types/sinon": "^17.0.3",
"@vitejs/plugin-react": "^4.3.4",
"chai-as-promised": "^8.0.1",
Expand Down
9 changes: 4 additions & 5 deletions packages/react-components-pro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"version": "tsx ../../scripts/package-json-version.ts"
},
"dependencies": {
"@lit/react": "^1.0.6",
"@vaadin/board": "24.7.0-alpha3",
"@vaadin/charts": "24.7.0-alpha3",
"@vaadin/cookie-consent": "24.7.0-alpha3",
Expand All @@ -39,10 +38,10 @@
"author": "Vaadin Ltd.",
"license": "SEE LICENSE IN LICENSE",
"peerDependencies": {
"@types/react": "^18.2.37 || ^19",
"@types/react-dom": "^18.2.15 || ^19",
"react": "^18.2.0 || ^19",
"react-dom": "^18.2.0 || ^19"
"@types/react": "^19",
"@types/react-dom": "^19",
"react": "^19",
"react-dom": "^19"
},
"peerDependenciesMeta": {
"@types/react": {
Expand Down
28 changes: 23 additions & 5 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"version": "tsx ../../scripts/package-json-version.ts"
},
"dependencies": {
"@lit/react": "^1.0.6",
"@vaadin/a11y-base": "24.7.0-alpha3",
"@vaadin/accordion": "24.7.0-alpha3",
"@vaadin/app-layout": "24.7.0-alpha3",
Expand Down Expand Up @@ -90,10 +89,10 @@
"author": "Vaadin Ltd.",
"license": "Apache-2.0",
"peerDependencies": {
"@types/react": "^18.2.37 || ^19",
"@types/react-dom": "^18.2.15 || ^19",
"react": "^18.2.0 || ^19",
"react-dom": "^18.2.0 || ^19"
"@types/react": "^19",
"@types/react-dom": "^19",
"react": "^19",
"react-dom": "^19"
},
"peerDependenciesMeta": {
"@types/react": {
Expand Down Expand Up @@ -493,6 +492,10 @@
"./css/material/Shadow.css": "./css/material/Shadow.css",
"./css/material/Typography.css": "./css/material/Typography.css",
"./css/material/UserColors.css": "./css/material/UserColors.css",
"./utils/addOrUpdateEventListener.d.ts": "./utils/addOrUpdateEventListener.d.ts",
"./utils/addOrUpdateEventListener.d.ts.map": "./utils/addOrUpdateEventListener.d.ts.map",
"./utils/addOrUpdateEventListener.js": "./utils/addOrUpdateEventListener.js",
"./utils/addOrUpdateEventListener.js.map": "./utils/addOrUpdateEventListener.js.map",
"./utils/createComponent.d.ts": "./utils/createComponent.d.ts",
"./utils/createComponent.d.ts.map": "./utils/createComponent.d.ts.map",
"./utils/createComponent.js": "./utils/createComponent.js",
Expand All @@ -501,6 +504,10 @@
"./utils/createComponentWithOrderedProps.d.ts.map": "./utils/createComponentWithOrderedProps.d.ts.map",
"./utils/createComponentWithOrderedProps.js": "./utils/createComponentWithOrderedProps.js",
"./utils/createComponentWithOrderedProps.js.map": "./utils/createComponentWithOrderedProps.js.map",
"./utils/flushInMicrotask.d.ts": "./utils/flushInMicrotask.d.ts",
"./utils/flushInMicrotask.d.ts.map": "./utils/flushInMicrotask.d.ts.map",
"./utils/flushInMicrotask.js": "./utils/flushInMicrotask.js",
"./utils/flushInMicrotask.js.map": "./utils/flushInMicrotask.js.map",
"./utils/flushMicrotask.d.ts": "./utils/flushMicrotask.d.ts",
"./utils/flushMicrotask.d.ts.map": "./utils/flushMicrotask.d.ts.map",
"./utils/flushMicrotask.js": "./utils/flushMicrotask.js",
Expand All @@ -514,9 +521,16 @@
"./utils/useMergedRefs.js": "./utils/useMergedRefs.js",
"./utils/useMergedRefs.js.map": "./utils/useMergedRefs.js.map",
"./renderers/combobox.d.ts": "./renderers/combobox.d.ts",
"./renderers/createRendererCallback.d.ts": "./renderers/createRendererCallback.d.ts",
"./renderers/createRendererCallback.d.ts.map": "./renderers/createRendererCallback.d.ts.map",
"./renderers/createRendererCallback.js": "./renderers/createRendererCallback.js",
"./renderers/createRendererCallback.js.map": "./renderers/createRendererCallback.js.map",
"./renderers/grid.d.ts": "./renderers/grid.d.ts",
"./renderers/multiSelectCombobox.d.ts": "./renderers/multiSelectCombobox.d.ts",
"./renderers/renderer.d.ts": "./renderers/renderer.d.ts",
"./renderers/renderer.d.ts.map": "./renderers/renderer.d.ts.map",
"./renderers/renderer.js": "./renderers/renderer.js",
"./renderers/renderer.js.map": "./renderers/renderer.js.map",
"./renderers/useContextRenderer.d.ts": "./renderers/useContextRenderer.d.ts",
"./renderers/useContextRenderer.d.ts.map": "./renderers/useContextRenderer.d.ts.map",
"./renderers/useContextRenderer.js": "./renderers/useContextRenderer.js",
Expand All @@ -529,6 +543,10 @@
"./renderers/useRenderer.d.ts.map": "./renderers/useRenderer.d.ts.map",
"./renderers/useRenderer.js": "./renderers/useRenderer.js",
"./renderers/useRenderer.js.map": "./renderers/useRenderer.js.map",
"./renderers/useRendererCallback.d.ts": "./renderers/useRendererCallback.d.ts",
"./renderers/useRendererCallback.d.ts.map": "./renderers/useRendererCallback.d.ts.map",
"./renderers/useRendererCallback.js": "./renderers/useRendererCallback.js",
"./renderers/useRendererCallback.js.map": "./renderers/useRendererCallback.js.map",
"./renderers/useSimpleOrChildrenRenderer.d.ts": "./renderers/useSimpleOrChildrenRenderer.d.ts",
"./renderers/useSimpleOrChildrenRenderer.d.ts.map": "./renderers/useSimpleOrChildrenRenderer.d.ts.map",
"./renderers/useSimpleOrChildrenRenderer.js": "./renderers/useSimpleOrChildrenRenderer.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/react-components/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type ComponentType,
type ForwardedRef,
forwardRef,
type HTMLAttributes,
isValidElement,
type ReactElement,
type ReactNode,
Expand Down Expand Up @@ -31,7 +32,7 @@ function Select(props: SelectProps, ref: ForwardedRef<SelectElement>): ReactElem

// Components with slot attribute should stay in light DOM.
const slottedChildren = children.filter((child): child is ReactNode => {
return isValidElement(child) && child.props.slot;
return isValidElement<HTMLAttributes<unknown>>(child) && !!child.props.slot;
});

// Component without slot attribute should go to the overlay.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/src/renderers/useRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function useRenderer<P extends {}, W extends WebComponentRenderer>(
convert?: (props: Slice<Parameters<W>, 1>) => PropsWithChildren<P>,
config?: RendererConfig<W>,
): UseRendererResult<W> {
const [map, update] = useReducer<typeof rendererReducer<W>>(rendererReducer, initialState);
const [map, update] = useReducer(rendererReducer, initialState);
const renderer = useCallback(
((...args: Parameters<W>) => {
if (config?.renderMode === 'microtask') {
Expand Down
30 changes: 30 additions & 0 deletions packages/react-components/src/utils/addOrUpdateEventListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const listenedEvents = new WeakMap<Element, Map<string, EventListenerObject>>();

export default function addOrUpdateEventListener(
node: Element,
event: string,
listener: ((event: Event) => void) | undefined,
) {
let nodeEvents = listenedEvents.get(node);
if (nodeEvents === undefined) {
nodeEvents = new Map();
listenedEvents.set(node, nodeEvents);
}

let handler = nodeEvents.get(event);
if (listener !== undefined) {
if (handler === undefined) {
// If necessary, add listener and track handler
handler = { handleEvent: listener };
node.addEventListener(event, handler);
nodeEvents.set(event, handler);
} else {
// Otherwise just update the listener with new value
handler.handleEvent = listener;
}
} else if (handler !== undefined) {
// Remove listener if one exists and value is undefined
node.removeEventListener(event, handler);
nodeEvents.delete(event);
}
}
Loading
Loading