Skip to content

Commit

Permalink
Merge pull request #218 from gigabo/root-attributes
Browse files Browse the repository at this point in the history
Update root container attributes on `reuseDom` client transition
  • Loading branch information
gigabo committed May 25, 2016
2 parents 711902c + 9ea54a8 commit f937d54
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react-server-test-pages/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// Your method will be defaulted to "get".
// The default `description` is your route _key_.
module.exports = {
RootAttributes: {
entry: "/root/attributes",
description: "Attributes on root elements and containers",
},
RootWhen: {
entry: "/root/when",
description: "<RootElement when={...}>",
Expand Down
28 changes: 28 additions & 0 deletions packages/react-server-test-pages/pages/root/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {RootContainer, RootElement, Link} from "react-server";

const url = color => `/root/attributes?color=${color}`;

const Links = opts => <span>
<Link path={url( "red" )} {...opts}>Red</ Link><span> | </span>
<Link path={url( "yellow" )} {...opts}>Yellow</ Link><span> | </span>
<Link path={url( "green" )} {...opts}>Green</ Link>
</span>

export default class RootAttributesPage {
getElements() {
const color = this.getRequest().getQuery().color || "white";
const style = `background-color: ${color}`;
return <RootContainer>
<div>Background below the hr should be <em>{color}</em></div>
<div><Links /> (normal)</div>
<div><Links reuseDom={true}/> (reuseDom)</div>
<hr />
<RootContainer style={style}>
<div>RootContainer</div>
</RootContainer>
<RootElement style={style}>
<div>RootElement</div>
</RootElement>
</RootContainer>
}
}
8 changes: 8 additions & 0 deletions packages/react-server/core/ClientController.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ class ClientController extends EventEmitter {
//
if (this._reuseDom && element.containerOpen && oldRootContainer) {
mountNode = oldRootContainer;
this._updateContainerNodeAttributes(
mountNode,
element.containerOpen
);
} else if (this._reuseDom && element.containerClose && !oldRootContainer && !oldRootElement) {
mountNode = mountNode.parentNode;
} else if (this._reuseDom && oldRootElement) {
Expand Down Expand Up @@ -737,6 +741,10 @@ class ClientController extends EventEmitter {
return node;
}

_updateContainerNodeAttributes(node, attrs) {
_.forEach(attrs, (v, k) => node.setAttribute(k, v));
}

init () {

var unloadHandler = () => {this.terminate(); };
Expand Down

0 comments on commit f937d54

Please sign in to comment.