Skip to content

Commit 7ff3fae

Browse files
committed
chore(rendered-content): nested html under rendered-content
to make room for additional content from custom rendering functions BREAKING CHANGE: the shape of rendered content has changed from a string to an object. the previous string content is now provided as an `html` property of the object
1 parent a532754 commit 7ff3fae

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

example/layout.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
</head>
77
<body>
8-
<div id="wrap"><div>{{{ renderedContent }}}</div></div>
8+
<div id="wrap"><div>{{{ renderedContent.html }}}</div></div>
99
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"> </script>
1010
</body>
1111
</html>

src/router-wrapper.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ export default async function renderThroughReactRouter(request, h, {routes, resp
2727
return respond(h, {
2828
store,
2929
status,
30-
renderedContent: renderToString((
31-
<Root request={request} store={store}>
32-
<RouterContext {...renderProps} />
33-
</Root>
34-
))
30+
renderedContent: {
31+
html: renderToString((
32+
<Root request={request} store={store}>
33+
<RouterContext {...renderProps} />
34+
</Root>
35+
))
36+
}
3537
});
3638
}
3739
} catch (e) {

test/integration/features/step_definitions/render-steps.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import {OK} from 'http-status-codes';
22
import {assert} from 'chai';
33
import {When, Then} from 'cucumber';
44

5-
When('a request is made for an existing route', function () {
5+
When(/^a request is made for an existing route$/, function () {
66
return this.makeRequest({url: '/existing-route'});
77
});
88

9-
Then('the route is rendered successfully', function (callback) {
9+
Then(/^the route is rendered successfully$/, function (callback) {
1010
assert.equal(this.serverResponse.statusCode, OK);
1111
assert.equal(this.serverResponse.headers['content-type'], 'text/html; charset=utf-8');
1212

1313
callback();
1414
});
1515

16-
Then('asynchronously fetched data is included in the page', function (callback) {
16+
Then(/^asynchronously fetched data is included in the page$/, function (callback) {
1717
assert.include(this.serverResponse.payload, this.dataPoint);
1818

1919
callback();

test/unit/router-wrapper-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ suite('router-wrapper', () => {
3838
const status = any.integer();
3939
const context = any.simpleObject();
4040
const rootComponent = any.simpleObject();
41-
const renderedContent = any.string();
41+
const html = any.string();
4242
const response = any.string();
4343
routeMatcher.default.withArgs(url, routes).resolves({renderProps, status});
4444
dataFetcher.default.withArgs({renderProps, store, status}).resolves({renderProps, status});
4545
React.createElement.withArgs(RouterContext, sinon.match(renderProps)).returns(context);
4646
React.createElement.withArgs(Root, {request, store}).returns(rootComponent);
47-
domServer.renderToString.withArgs(rootComponent).returns(renderedContent);
48-
respond.withArgs(reply, {renderedContent, store, status}).returns(response);
47+
domServer.renderToString.withArgs(rootComponent).returns(html);
48+
respond.withArgs(reply, {renderedContent: {html}, store, status}).returns(response);
4949

5050
return assert.becomes(renderThroughReactRouter(request, reply, {routes, respond, Root, store}), response);
5151
});

0 commit comments

Comments
 (0)