-
Notifications
You must be signed in to change notification settings - Fork 417
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
feat(solid): initial draft implementation #1096
base: master
Are you sure you want to change the base?
Conversation
|
packages/solid/src/styled.ts
Outdated
>; | ||
}; | ||
|
||
export declare const styled: Styled & StyledJSXIntrinsics; |
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.
This is an oversimplified version of styled
. Why we can't use the original one from @linaria/react
?
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.
I don't remember exactly, but there were some rare cases where typings just didn't work (props just didn't type check). I'll try to find that case.
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.
Here's a simple comparison of the old signature and the new one (simplified).
On the left is original, on the right - new.
- T1:
foo
prop is allowed in original whereas it's not allowed in the new because it's not declared; - T2:
bar
is now not allowed in original, maybe because the component now has props; it's still not allowed in new because it's not declared; - T3: mostly the same as
T1
-foo
is not declared but is allowed in original; note -bar
is allowed innew
because type checker fails fast on thefoo
prop, it still rejectsbar
iffoo
is removed because none of them are declared - T4: this case is not supported at all in original
- T5: this case is not supported at all in original
- T6: this case is not supported at all in original
@Anber how about shipping simplified typings first and see how it goes/gather some feedback later?
Work in progress on this thread? |
@usmanyunusov yeah, in progress but I have very little time now to work on it. |
# Conflicts: # pnpm-lock.yaml
@Anber smth weird is happening to test snapshots in What's interesting is that it's fine on |
ok, I finished the basic example built with |
@Anber ready for review |
@Anber thanks for enabling the CI on this PR 🙏 |
🙏 |
when can i expect this feature release? |
I just tested it quickly and don't fully understand solid, please correct me if I'm wrong. const HelloWorldSolid = () => {
const [count, setCount] = createSignal(0);
return (
<div>
<Heading style={{"margin-top": `${count()}px`}}>
count: {count()}
</Heading>
<button onClick={() => setCount((c) => c + 1)}> increment</button>
</div>
);
};
const Heading = styled.h1`
background: red;
`; The text in the heading updates correctly, but the margin is not applied. edit: |
Is this PR abandoned? |
What's up with this PR? |
just use tw/unocss + attributify |
This is just another DSL. I am looking for a way to write actual CSS, not tailwind shorthands in made up attributes that may or may not clash with actual JSX props or HTML attributes |
There are some drawbacks, but I think it's much better then using linaria. You don't need this rocket-science euristic compilier that slows down dev builds and potentially breaks your code. You can start with simple pure I spent year with unocss after linaria and it feels so much better to work with. |
@MrFoxPro let's keep this PR focused on linaria and solid. This is not the right place to promote failwind or any other framework. |
@Tetrax-10 @NightmanCZ90 @ivancuric I see all your comments here but unfortunately I don't have spare time to work on this. Your are kindly welcome to take on the initiative here 🙏 |
Motivation
This PR introduces an initial implementation of linaria processor for solid.
Summary
The idea is to completely eliminate any extra runtime components and transpile the code into intermediate representation suitable for further transpilation with solid (this means, the processor doesn't transpile the code down to solid's output, it should be the responsibility of the end developer to pipe transformations correctly: first goes @linaria/solid, then the code must be transformed by solid with either babel plugin, vite plugin etc.)
Test plan
The tests are not working at the moment as it turns out it's quite hard to write any meaningful tests without the actual transpilation step. Testing snapshots seems too fragile and unmaintainable.
Instead I tried to take an approach on transpiling the code of tests with linaria+solid in a custom jest transform. It works but I'd still like to avoid testing stringified (or jsonified) output. Instead, it would be really cool to make use of JSDom to run the output, render generated components and test interaction with them. E.g. a reactive prop on a component must update components runtime structure etc.
At the moment I'm able to transpile the code with both jest transform (seamlessly transpiles the whole test and we can use regular TSX to write the code - huge win) and with a custom transpile step (takes a stringified input and transpiles down to solid's output - not so good as we lose TSX and still need to eval the code somehow).
Another thing to consider is that jest transform throws away generated css and I'd like to render it with JSDom so that interactions with components can be fully tested (e.g. when we set a prop on a component, component's color turns blue).
But this would require adding a build step with esbuild/vite/etc and somehow integrate it into jest+jsdom - the first thing that comes to mind is a custom jest environment based on jest-environment-jsdom, this might work. Also we could take a look at
@testing-library/react
and see what they are doing and try to implement the same things in the jest environment.All these turned out to be much more work, so I stopped on that as unfortunately I don't have enough time at the moment.
Still, I'm opening the PR to demonstrate possible implementation of processor, as @Anber suggested in DM 👌