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

Hydration #37

Open
srghma opened this issue May 13, 2020 · 3 comments · May be fixed by #38 or #54
Open

Hydration #37

srghma opened this issue May 13, 2020 · 3 comments · May be fixed by #38 or #54

Comments

@srghma
Copy link

srghma commented May 13, 2020

I have mentioned it here purescript-halogen/purescript-halogen#610 (comment)

just like for:

  1. https://reactjs.org/docs/react-dom.html#hydrate
  2. https://github.com/snabbdom/snabbdom/blob/master/src/tovnode.ts

The second link is just for reference. It builds VDOM from DOM node, but our hydrate method should

  1. take DOM element
  2. take VDOM element that contains event handlers
  3. add event handlers to the DOM elements recursively AND throw error if the content of the DOM element is different from the VDOM (for example the text or class property)
@natefaubion
Copy link
Collaborator

This would be possible by having alternative build functions to initialize the vdom machines. For example:

buildText a w. VDomBuilder String a w
buildText = EFn.mkEffectFn3 \(VDomSpec spec) build s → do
node ← EFn.runEffectFn2 Util.createTextNode s spec.document
let state = { build, node, value: s }
pure $ mkStep $ Step node state patchText haltText

This creates a text node, but a hypothetical hydration implementation would check the DOM for an existing node first and reuse that.

@srghma srghma linked a pull request May 13, 2020 that will close this issue
@srghma
Copy link
Author

srghma commented May 14, 2020

I have found that prerendered html should not contain any newlines

because

with

  <div id="app">
    <div class="component">
      <div class="label1">test label 1</div>
      <div class="label2">test label 2</div>
    </div>
  </div>

componentNode.childNodes will return newspaces too

the correct version is

  <div id="app">
    <div class="component"><div class="label1">test label 1</div><div class="label2">test label 2</div></div>
  </div>

react does the same https://jsbin.com/majoxoqoje/edit?html,js,console,output

2020-05-14-20:59:55-screenshot


extraAttributeNames are defined here https://github.com/facebook/react/blob/823dc581fea8814a904579e85a62da6d18258830/packages/react-dom/src/client/ReactDOMComponent.js#L1029-L1050

unknown props are downcased and removed https://github.com/facebook/react/blob/823dc581fea8814a904579e85a62da6d18258830/packages/react-dom/src/client/ReactDOMComponent.js#L1134

@purefunctor purefunctor linked a pull request Jun 15, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants