r/solidjs • • 3d ago

I made a `solid-composition-patterns` skill for Solid 2

I've been working on a skill called solid-composition-patterns. The idea came from Vercel's vercel-composition-patterns for React. I wanted the same thing for Solid, basically keeping reusable components and design system primitives clean and scalable instead of letting them turn into a mess of props.

Everything in there is written for Solid 2's model. It covers things like preserving fine-grained proxy reactivity, compound components, lifting state and mutations into { state, actions, meta } providers, and handling async boundaries with <Loading> and <Errored>.

This skill was originally built for Solid 1, but while experimenting with migrating one of my projects, I took what I learned along the way and reworked it around Solid 2. I also purposely left out any mention of Solid 1 APIs or old patterns so the agent doesn't get confused and fall back into v1 habits.

You can check it out on skills.sh or GitHub.

Solid 2 is still pretty new, so if you notice any edge cases, missed idioms, or anything that feels off, I'd love to hear your thoughts.

16 Upvotes

4 comments sorted by

2

u/Blue_Krow 2d ago

Am I missing something about the "Lift State into Provider Components" examples? (skills/skills/solid-composition-patterns/rules/state-lift-state.md at 94ca538559e312a8d3f7268221f858051d898938 · Pkcarreno/skills) It says:

In Solid 2.0, lifting state into a provider adds zero component re-render cost because components execute once and only fine-grained DOM/effect bindings re-run when read signals change.

It seems to me that it's conflating two things: lifting state upwards and using context providers. Context is a mechanism to pass props down implicitly to avoid prop drilling at the cost of, well, making the dependency implicit, which makes things less readable. I would have written the "Correct" example as follows:

import { createSignal, createStore } from 'solid-js';

function ForwardMessageDialog() {
  const [input, setInput] = createSignal('');
  const [submitting, isSubmitting] = createSignal(false);
  const [attachments, setAttachments] = createStore<Attachment[]>([]);

  const submit = async () => {
    setIsSubmitting(true);
    await api.forwardMessage(input());
    setIsSubmitting(false);
  };

  return (
    <Dialog>
      <Composer.Frame>
        <Composer.Input />
      </Composer.Frame>
      <MessagePreview message={input}/>
      <DialogFooter>
        <ForwardButton disabled={submitting} onClick={submit} />
      </DialogFooter>
    </Dialog>
  );
}

function MessagePreview(props) {
  return <div class="preview">{props.message}</div>;
}

function ForwardButton(props) {
  return (
    <button type="button" disabled={props.disabled} onClick={props.onClick}>
      Forward
    </button>
  );
}

Less code, more explicit about intention, and same performance characteristics.

I'd even argue that the "syncing local child state upward with effects and callback props" strategy is valid when you want to create a reusable component that doesn't know whether it owns its own state.

2

u/pkcarreno 1d ago

Fair point, I agree that for a one-off component, lifting state and passing explicit props is simpler and easier to follow.

I kept the provider structure mostly to stay consistent with how vercel-composition-patterns approaches it. Even though Solid doesn't have the same re-render penalty as React, I find the provider pattern cleaner when building compound components and design system primitives that need to scale across nested wrappers without prop drilling.

I'll admit the skill is a bit opinionated toward my own habits there, and you're right that the wording makes it sound like lifting state and using context are the same thing. I might clarify that trade-off in the rule.

1

u/_dbase 3d ago

This is super neat! I’d love to see this discussed in our Discord and even added to the ecosystem page on your website. Instructions for doing so are on the site itself.

Going to give this a spin myself as well.

1

u/pkcarreno 2d ago

Thanks a lot! Hope you find it useful.

I'm not really a big Discord user, but I'll definitely take a look. As for the ecosystem page, I wasn't sure if a skill really fits under libraries or packages, so I'll open an issue about adding an AI tools category to see if there's interest. That way other AI utilities could get some visibility too.