#Hydration Mismatch

10 messages · Page 1 of 1 (latest)

bronze schooner
#
function Test() {
    return <div>test</div>;
}
function Main() {
    const a = Test(); 
    return (
        <>
        </>
    );
}

Why this can cause Error: Hydration Mismatch. Unable to find DOM nodes for hydration key: s00-0-0-0

EDIT:
The component constructed before return in the function body must be used in the return html. Otherwise, it will cause the Hydration Mismatch error.

This issue will disable the Show logic for the component.
Neither

<Show when={should_show()}>
  {a}
</Show>

or

{should_show() ? a : undefined}

can be used. Both of them will cause the Hydration Mismatch error.

maiden pendant
#

use children to render a child as a signal. But your example is too concise to be of any help toward your goal

bronze schooner
bronze schooner
maiden pendant
white grail
# bronze schooner ```jsx function Test() { return <div>test</div>; } function Main() { con...

Perhaps using a render thunk will work for you:

import { render } from 'solid-js/web';
import { createResource, Show, Suspense } from 'solid-js';

function fakeAsyncOp() {
  return new Promise<string>((r) => setTimeout(r, 2000, 'Done'));
}

function Test(props: { content: string }) {
  return <p>{props.content}</p>;
}

function App() {
  // deferStream works with createAsync as well
  const [result] = createResource(fakeAsyncOp, { deferStream: true });

  // This is the important part
  const renderFn = () => <Test content={result() ?? `don't care`} />;

  return (
    <>
      <h1>Hi there!</h1>
      <Suspense fallback={<p>loading…</p>}>
        <Show when={result() ? renderFn : undefined}>{(fn) => fn()()}</Show>
      </Suspense>
    </>
  );
}

render(() => <App />, document.getElementById('app')!);

https://playground.solidjs.com/anonymous/6ca2a1bd-eb77-4647-b822-8881ac7b0320

maiden pendant
white grail
bronze schooner
bronze schooner