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

fix: SolidJS reactivity warnings #494

Draft
wants to merge 4 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
23 changes: 10 additions & 13 deletions src/solid/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { ItemResizeObserver } from "../core/resizer";
import { isRTLDocument } from "../core/environment";
import {
Component,
JSX,
type Component,
type JSX,
createEffect,
createMemo,
mergeProps,
Expand All @@ -29,28 +29,25 @@ interface ListItemProps {
*/
export const ListItem: Component<ListItemProps> = (props) => {
let elementRef: HTMLDivElement | undefined;
props = mergeProps<[Partial<ListItemProps>, ListItemProps]>(
{ _as: "div" },
props
);
const mergedProps = mergeProps({ _as: "div" }, props);

// The index may be changed if elements are inserted to or removed from the start of props.children
// The index may be changed if elements are inserted to or removed from the start of mergedProps.children
createEffect(() => {
if (!elementRef) return;
onCleanup(props._resizer(elementRef, props._index));
onCleanup(mergedProps._resizer(elementRef, mergedProps._index));
});

const style = createMemo(() => {
const isHorizontal = props._isHorizontal;
const isHorizontal = mergedProps._isHorizontal;
const style: JSX.CSSProperties = {
margin: 0,
padding: 0,
position: "absolute",
[isHorizontal ? "height" : "width"]: "100%",
[isHorizontal ? "top" : "left"]: "0px",
[isHorizontal ? (isRTLDocument() ? "right" : "left") : "top"]:
props._offset + "px",
visibility: props._hide ? "hidden" : "visible",
mergedProps._offset + "px",
visibility: mergedProps._hide ? "hidden" : "visible",
};
if (isHorizontal) {
style.display = "flex";
Expand All @@ -59,8 +56,8 @@ export const ListItem: Component<ListItemProps> = (props) => {
});

return (
<Dynamic component={props._as} ref={elementRef} style={style()}>
{props._children}
<Dynamic component={mergedProps._as} ref={elementRef} style={style()}>
{mergedProps._children}
</Dynamic>
);
};
12 changes: 6 additions & 6 deletions src/solid/RangedFor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
createRoot,
createSignal,
onCleanup,
JSX,
Signal,
Accessor,
type JSX,
type Signal,
type Accessor,
} from "solid-js";
import { ItemsRange } from "../core/types";
import type { ItemsRange } from "../core/types";

interface RenderedNode<T> {
_data: Signal<T>;
Expand All @@ -37,7 +37,7 @@
}
});

return createMemo(() => {

Check warning on line 40 in src/solid/RangedFor.tsx

View workflow job for this annotation

GitHub Actions / check

For proper analysis, a variable should be used to capture the result of this function call
const list = props._each;
const [start, end] = props._range;
const current = new Map<number, RenderedNode<T>>();
Expand All @@ -50,7 +50,7 @@
lookup
? lookup._element
: createRoot((dispose) => {
const data = createSignal(newData);

Check warning on line 53 in src/solid/RangedFor.tsx

View workflow job for this annotation

GitHub Actions / check

For proper analysis, array destructuring should be used to capture the first result of this function call
const result = props._render(data[0], i);
current.set(i, {
_data: data,
Expand All @@ -58,12 +58,12 @@
_dispose: dispose,
});
return result;
})
}),
);
if (lookup) {
if (newData !== lookup._data) {
lookup._data[1](
newData as Exclude<T, Function> // TODO improve type
newData as Exclude<T, Function>, // TODO improve type
);
}
current.set(i, lookup);
Expand Down
61 changes: 30 additions & 31 deletions src/solid/VList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* @jsxImportSource solid-js
*/
import { JSX } from "solid-js";
import { ViewportComponentAttributes } from "./types";
import { type JSX, splitProps } from "solid-js";
import type { ViewportComponentAttributes } from "./types";
import {
Virtualizer,
VirtualizerHandle,
VirtualizerProps,
type VirtualizerHandle,
type VirtualizerProps,
} from "./Virtualizer";

/**
Expand Down Expand Up @@ -37,45 +37,44 @@ export interface VListProps<T>
* Virtualized list component. See {@link VListProps} and {@link VListHandle}.
*/
export const VList = <T,>(props: VListProps<T>): JSX.Element => {
const {
ref,
data,
children,
overscan,
itemSize,
shift,
horizontal,
onScroll,
onScrollEnd,
onRangeChange,
style,
...attrs
} = props;
const [local, ...attrs] = splitProps(props, [
"ref",
"data",
"children",
"overscan",
"itemSize",
"shift",
"horizontal",
"onScroll",
"onScrollEnd",
"onRangeChange",
"style",
]);

return (
<div
{...attrs}
style={{
display: horizontal ? "inline-block" : "block",
[horizontal ? "overflow-x" : "overflow-y"]: "auto",
display: local.horizontal ? "inline-block" : "block",
[local.horizontal ? "overflow-x" : "overflow-y"]: "auto",
contain: "strict",
width: "100%",
height: "100%",
...props.style,
...local.style,
}}
>
<Virtualizer
ref={props.ref}
data={props.data}
overscan={props.overscan}
itemSize={props.itemSize}
shift={props.shift}
horizontal={horizontal}
onScroll={props.onScroll}
onScrollEnd={props.onScrollEnd}
onRangeChange={props.onRangeChange}
ref={local.ref}
data={local.data}
overscan={local.overscan}
itemSize={local.itemSize}
shift={local.shift}
horizontal={local.horizontal}
onScroll={local.onScroll}
onScrollEnd={local.onScrollEnd}
onRangeChange={local.onRangeChange}
>
{props.children}
{local.children}
</Virtualizer>
</div>
);
Expand Down
Loading
Loading