-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Themes: Use details
middleware for server-side rendering
#3562
Themes: Use details
middleware for server-side rendering
#3562
Conversation
5091c86
to
f71f418
Compare
Getting
@mcsf @ehg @seear Any experience from past |
NMR it, and seek an upstream fix :) |
Been there, it seems: |
Hmm, just adding |
|
Right, so the way we're trying to avoid loading non-iso-compatible controllers is suspect.
What I imagined was having separate node/web controllers, so this wouldn't happen. Maybe put all SSR-compatible controllers/middleware in FWIW, I think we can solve the |
Object.assign( context, render( context.layout ) ); | ||
} | ||
context.res.render( 'index.jade', context ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should move this function to server/render
, I think.
7d15e15
to
965fd4f
Compare
Rebasing this on |
ef15ccd
to
d2af217
Compare
21e597f
to
791bcde
Compare
compose( ...liftedmiddlewares )(); | ||
} | ||
|
||
function compose( ...functions ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use lodash's flowRight
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(For the record, flowRight
wasn't fit for a drop-in replacement. It was agreed that having this local implementation is fine.)
<ThemeDetailsComponent id={ themeSlug } section={ contentSection } > | ||
<ThemeSheetComponent /> | ||
</ThemeDetailsComponent> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're redeclaring a component on each middleware call here.
Add a `package.json` that sets different entry points on the server and in the browser (not everything required by `my-sites/themes/index.js` is SSR-ready yet, so we need a pruned version for the server).
In the `/design` and `/themes` routes in `server/pages`, use `my-sites/themes` to create element trees in `context.layout`, and `renderToString()` that. * Adapt `express`'s `req` context to be able to use it with middleware that otherwise operates on `page`'s `context` (props @mcsf). * Add docs
To avoid confusion with `context.layout` holding a Layout *element*.
d72b9fd
to
0c6abfa
Compare
…ddleware-server-side Themes: Use `details` middleware for server-side rendering
In the
/themes
route inserver/pages
, usemy-sites/themes
to create a theme sheet element tree incontext.layout
, andrenderToString()
that.express
'sreq
context to be able to use it with middleware that otherwise operates onpage
'scontext
. props @mcsfpackage.json
that sets different entry points on the server and in the browser (not everything required bymy-sites/themes/index.js
is SSR-ready yet, so we need a pruned version for the server).my-sites/themes/controller/index.node.js
.renderToString
caching toserver/render
.title
etc are properly set.To test:
/theme/mood
, with JS disabled. Note that the title is now set to 'themeName
Theme — WordPress.com' (instead of the generic 'WordPress.com', as onmaster
)./design
and/themes/something
routes server-render the logged-out layout (masterbar!) before it's being replaced by the logged-in one on the client. While we want to fix this in the long run, it is no behavioral change frommaster
.Note:
master
. Opting to fix them later, since this PR is big enough already. (Possible cuplrit: Apparently,react-helmet
inserts anoscript
tag. server rendering returns <noscript></noscript> where <Helmet /> is implemented nfl/react-helmet#81)/design
. Also opting to fix later./cc @seear @ehg @mcsf
Follow-ups: #3302, #3774, #3795, #3425
I'd say this closes #185 :-)