-
Notifications
You must be signed in to change notification settings - Fork 375
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
[Bug?]: Hydration Mismatch during Development. Nesting element within an object will break hydration. #1475
Comments
Context: Original Discord discussion. TLDR: Feels that requiring a render thunk import type { JSX } from 'solid-js';
const ReproduceSteps = (props: {
test: {
propertyBesidesElement: () => JSX.Element;
element: () => JSX.Element;
};
}) => {
return (
<button onClick={() => console.log(props.test)}>
{props.test.propertyBesidesElement()}
</button>
);
};
export default function App() {
return (
<ReproduceSteps
test={{
propertyBesidesElement: () => 'test',
element: () => <div>test</div>,
}}
/>
);
} to support SSR is poor DX. |
The reason is that technically every time you call props.test you are remaking the DOM elements. Some are being inserted and the others aren't, and aren't being found. In the past we were more lenient here creating new DOM elements in these cases and just warning. But this isn't a good pattern anyway as you are basically doing wasted work by rendering twice. If you access props multiple times we recommend using |
Also, I see this as very risk approach, I don't to be recreating "consumer" elements all the time. Besides @peerreynders's recommendation, and "3 Patterns to Write Declarative, More Readable SolidJS Components", what are the alternatives? What is the best one to compose layouts off of consumer provided elements? I intend to contribute on the documentation, xD to put a very big warning there against this pattern, which I'm very used from React-based codebases. |
Duplicates
Latest version
Current behavior 😯
Route throws consistently when accessing it during development, any time the route is accessed. Production build seems to work fine. Anticipating this question, it doesn't influences at all, restarting the server doesn't affect it..
Expected behavior 🤔
It shouldn't throw.
Steps to reproduce 🕹
Steps:
dev
modeContext 🔦
I've reduced it to the minimal reproducible code. Let me know if anything else is required. Couldn't find this same bug on other issues so I decided to report.
Your environment 🌎
The text was updated successfully, but these errors were encountered: