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

ssr/hydration: keep markup created by custom elements in the dom #764

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,14 @@ export function app(state, actions, view, container) {
}
}

while (i < oldChildren.length) {
if (getKey(oldChildren[i]) == null) {
removeElement(element, oldElements[i], oldChildren[i])
var isCustomElement = element.nodeName.indexOf("-") !== -1
if (!isRecycling && !isCustomElement) {
while (i < oldChildren.length) {
if (getKey(oldChildren[i]) == null) {
removeElement(element, oldElements[i], oldChildren[i])
}
i++
}
i++
}

for (var i in oldKeyed) {
Expand Down
49 changes: 49 additions & 0 deletions test/recycling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,52 @@ test("recycle markup against keyed vdom", done => {
document.getElementById("app")
)
})

test("recycle custom-elements inner markup to support non-native shadowdom polyfills", done => {
const SSR_HTML = `<div id="app"><main><custom-element>fake shadowdom</custom-element></main></div>`

document.body.innerHTML = SSR_HTML

app(
null,
null,
state => (
<main>
<custom-element
oncreate={element => {
expect(element.innerHTML).toBe("fake shadowdom")
expect(document.body.innerHTML).toBe(SSR_HTML)
done()
}}
/>
</main>
),
document.getElementById("app")
)
})

test("hydrate custom elements children defined in the view", done => {
const SSR_HTML = `<div id="app"><main><custom-element><hr id="foo"></custom-element></main></div>`

document.body.innerHTML = SSR_HTML

app(
null,
null,
state => (
<main>
<custom-element>
<hr
id="foo"
oncreate={element => {
expect(element.id).toBe("foo")
expect(document.body.innerHTML).toBe(SSR_HTML)
done()
}}
/>
</custom-element>
</main>
),
document.getElementById("app")
)
})