Skip to content

Hydration #38

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

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b385b50
refactor: add comments, better names for arguments
srghma May 13, 2020
9090846
feat: hydration -> WIP
srghma May 13, 2020
e29ca5c
feat: hydration -> WIP
srghma May 13, 2020
fdbd777
refactor: use web-dom
srghma May 14, 2020
4e38782
refactor: length
srghma May 14, 2020
e4557f4
refactor: wip
srghma May 14, 2020
8e99a8b
refactor: working without props
srghma May 14, 2020
bbf6ec2
refactor: DOM.Prop -> move functions outside of buildProp, add el and…
srghma May 14, 2020
c323602
refactor: DOM.Prop -> move functions to different modules
srghma May 14, 2020
308f146
feat: hydration -> wip, changed type of unsafeGetProperty from `Fn.Fn…
srghma May 16, 2020
477b9c4
feat: hydration -> works on test
srghma May 16, 2020
8ccb492
feat: hydration -> impl for keyed, not tested
srghma May 16, 2020
7689b19
feat: test keyed implementation
srghma May 16, 2020
ad68113
feat: hydration -> implement for widgets and thunks
srghma May 16, 2020
40494f7
feat: props -> move checkers to separate module
srghma Jun 2, 2020
6764603
refactor: warnings -> resolve
srghma Jun 2, 2020
c17301b
revert(#b385b50)
srghma Jun 3, 2020
6722152
refactor: thunk
srghma Jun 3, 2020
d085471
refactor: move comment where it belongs
srghma Jun 3, 2020
3fb49b1
feat: create Halogen.VDom.Finders
srghma Jun 4, 2020
b98e648
feat: check extra attributes
srghma Jun 4, 2020
6a9e94b
feat: tracing
srghma Jun 10, 2020
204e4c6
feat: deleteRequiredElement
srghma Jun 16, 2020
42cb725
fix: href property on <a> element
srghma Jun 16, 2020
cfd471e
fix: error `expected false, but got true` on `<button disabled></butt…
srghma Jun 16, 2020
1e8a342
refactor: comment
srghma Jun 16, 2020
a6f26a1
refactor: Prop.Utils to Prop.Util
srghma Jun 16, 2020
8c0fe08
feat: normalizeChildren
srghma Jun 16, 2020
1eba0b7
fix: use Node instead of Element for root node, more type safety
srghma Jun 16, 2020
baab1d7
fix: normalizeChildren
srghma Jun 16, 2020
d074b41
fix: hydration -> hydrateElement -> split text on dom according to vd…
srghma Jun 17, 2020
30966ef
fix: hydration -> hydrateKeyed -> split text on dom according to vdom…
srghma Jun 17, 2020
fd94726
refactor: zipChildrenAndSplitTextNodes
srghma Jun 17, 2020
7e60c36
feat: spago
srghma Jun 18, 2020
be85696
feat: update comments
srghma Jun 19, 2020
dcdf4c9
feat: add traces
srghma Jun 21, 2020
953ba66
feat: split VDomSpec on VDomSpec and VDomSpecWithHydration
srghma Jun 24, 2020
4a1ac34
feat: remove debug, improve errors
srghma Jun 24, 2020
c0217b8
refactor: remove debug package
srghma Jun 24, 2020
50c315a
feat(#41): hydration -> additional props with name different from att…
srghma Jul 24, 2020
312ef16
fix: error with element with namespace "Expected element tagName equa…
srghma Jul 31, 2020
f98a5da
feat: namespaces -> dont check default namespace
srghma Aug 1, 2020
1cc8aef
fix: Cannot delete element "viewBox" that is not present in extraAttr…
srghma Aug 1, 2020
40b4034
fix: warnings
srghma Sep 7, 2020
bd7744e
fix: better errors -> show propsToHydrate
srghma Sep 8, 2020
2f5dc52
feat: rename set to jsset
srghma Oct 7, 2020
8970c5e
Merge branch 'master' into master
srghma Feb 2, 2021
cae26b5
feat: update to purescript 0.14, fix warnings
srghma Feb 3, 2021
b2486e1
feat: update comment for findElementFirstChild
srghma Mar 11, 2021
4116178
Merge remote-tracking branch 'upstream/master'
srghma Mar 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ package-lock.json
/bower_components/
/node_modules/
/output/
/app.js
/hydration-test.js
/yarn-error.log
41 changes: 41 additions & 0 deletions HOW_DOM_ATTRIBUTES_AND_PROPERTIES_WORK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# How .attributes work

`$0.attributes` are:
- <input required> is { required: "" }
- <input required="false"> is { required: "false" }
- <td colspan="1"> is { colspan: "1" }, but prop is colSpan = 1
- <div foo:data-foo="1"> is { "foo:data-foo": "1" }

# Properties

```
Having `<input type="text" value="foo1">`
If do `$0.required = true` in chrome.
THE html `<input type="text" value="foo1" required>`
THE $0.attributes = { required: "true" }
```

```
Having `<input type="text" value="foo1" required>`
If do `$0.required = false` in chrome.
THE html `<input type="text" value="foo1">`
THE $0.attributes = {}
```

# How .dataset property works? should we support it?

```
Having `<div id="1" data-foo="foo" data-bar="bar" data-baz-bak="baz-bak" data-someint="1"></div>`
The `$0.attributes`
`NamedNodeMap { id: "1", data-foo: "foo", data-bar: "bar", data-baz-bak: "baz-bak", someint: "1" }`
The `$0.dataset`
`DOMStringMap { foo: "foo", bar: "bar", bazBak: "baz-bak", someint: "1" }`
```

Also, react doesnt support dataset property during hydration. Proof:

- server = `<div id="1" data-foo="foo">`
- client = `<div id="1" dataset={{ foo : "foo" }}></div>`
- errorMessage = `Prop `dataset` did not match. Server: "null" Client: "[object Object]"`

thus, react does support `data-***` attributes, but doesn't support `dataset` property, so why bother with supporting `dataset` property?
25 changes: 25 additions & 0 deletions hydration-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>

<head>
<meta name="description" content="DBMON HALOGEN-VDOM" />
<meta charset="utf-8">
<title>hydration test</title>

<style>
.component { background-color: aquamarine; }
.label1 { color: red; }
.label2 { color: blue; }
</style>
</head>

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

<button id="update-state-button">Update state</button>
<script src="hydration-test.js"></script>
</body>

</html>
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"scripts": {
"clean": "rimraf output && rimraf",
"test": "pulp build -I test -- --censor-lib --strict",
"build": "pulp build -- --censor-lib --strict"
"build": "pulp build -- --censor-lib --strict",
"spago:test": "spago bundle-app --main Test.Main --to app.js",
"spago:hydration-test": "spago bundle-app --main Test.Hydration --to hydration-test.js",
"spago:test:watch": "yarn run spago:test --watch",
"spago:hydration-test:watch": "yarn run spago:hydration-test --watch"
},
"devDependencies": {
"pulp": "^15.0.0",
Expand Down
128 changes: 128 additions & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{-
Welcome to your new Dhall package-set!

Below are instructions for how to edit this file for most use
cases, so that you don't need to know Dhall to use it.

## Warning: Don't Move This Top-Level Comment!

Due to how `dhall format` currently works, this comment's
instructions cannot appear near corresponding sections below
because `dhall format` will delete the comment. However,
it will not delete a top-level comment like this one.

## Use Cases

Most will want to do one or both of these options:
1. Override/Patch a package's dependency
2. Add a package not already in the default package set

This file will continue to work whether you use one or both options.
Instructions for each option are explained below.

### Overriding/Patching a package

Purpose:
- Change a package's dependency to a newer/older release than the
default package set's release
- Use your own modified version of some dependency that may
include new API, changed API, removed API by
using your custom git repo of the library rather than
the package set's repo

Syntax:
Replace the overrides' "{=}" (an empty record) with the following idea
The "//" or "⫽" means "merge these two records and
when they have the same value, use the one on the right:"
-------------------------------
let overrides =
{ packageName =
upstream.packageName // { updateEntity1 = "new value", updateEntity2 = "new value" }
, packageName =
upstream.packageName // { version = "v4.0.0" }
, packageName =
upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" }
}
-------------------------------

Example:
-------------------------------
let overrides =
{ halogen =
upstream.halogen // { version = "master" }
, halogen-vdom =
upstream.halogen-vdom // { version = "v4.0.0" }
}
-------------------------------

### Additions

Purpose:
- Add packages that aren't already included in the default package set

Syntax:
Replace the additions' "{=}" (an empty record) with the following idea:
-------------------------------
let additions =
{ package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"tag ('v4.0.0') or branch ('master')"
}
, package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"tag ('v4.0.0') or branch ('master')"
}
, etc.
}
-------------------------------

Example:
-------------------------------
let additions =
{ benchotron =
{ dependencies =
[ "arrays"
, "exists"
, "profunctor"
, "strings"
, "quickcheck"
, "lcg"
, "transformers"
, "foldable-traversable"
, "exceptions"
, "node-fs"
, "node-buffer"
, "node-readline"
, "datetime"
, "now"
]
, repo =
"https://github.com/hdgarrood/purescript-benchotron.git"
, version =
"v7.0.0"
}
}
-------------------------------
-}


let upstream =
/home/srghma/projects/package-sets/src/packages.dhall

let overrides = {=}

let additions = {=}

in upstream // overrides // additions
28 changes: 28 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{-
Welcome to a Spago project!
You can edit this file as you like.
-}
{ name = "halogen-vdom"
, dependencies =
[ "bifunctors"
, "console"
, "effect"
, "exists"
, "foreign"
, "foreign-object"
, "js-timers"
, "maybe"
, "prelude"
, "psci-support"
, "refs"
, "tuples"
, "unsafe-coerce"
, "web-html"
, "web-dom"
, "strings"
, "control"
, "lazy"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}
2 changes: 1 addition & 1 deletion src/Halogen/VDom.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module Halogen.VDom
, module Types
) where

import Halogen.VDom.DOM (VDomSpec(..), buildVDom) as DOM
import Halogen.VDom.DOM (VDomSpec(..), VDomSpecWithHydration(..), buildVDom, hydrateVDom) as DOM
import Halogen.VDom.Machine (Machine, Step, Step'(..), mkStep, unStep, extract, step, halt) as Machine
import Halogen.VDom.Types (VDom(..), Graft, runGraft, ElemName(..), Namespace(..)) as Types
3 changes: 3 additions & 0 deletions src/Halogen/VDom/Attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.attributes = function (el) {
return el.attributes;
};
19 changes: 19 additions & 0 deletions src/Halogen/VDom/Attributes.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Halogen.VDom.Attributes where

import Prelude (Unit)

import Web.DOM.Element as DOM
import Effect.Uncurried as EFn
import Unsafe.Coerce (unsafeCoerce)
import Halogen.VDom.Util as Util

data NamedNodeMap

foreign import attributes ∷ DOM.Element → NamedNodeMap

forEachE
∷ EFn.EffectFn2
NamedNodeMap
(EFn.EffectFn1 { name :: String } Unit)
Unit
forEachE = unsafeCoerce Util.forEachE
Loading