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

Template compilation on the server (discussion) #16

Closed
wants to merge 7,260 commits into from

Conversation

gadicc
Copy link

@gadicc gadicc commented Mar 31, 2016

Is there any reason we don't already do this?

I made the changes in this PR and surprisingly everything just worked. Of course it needs a little more thought. Template.body.renderToDocument() is never called on the server but obviously that code shouldn't be bundled for the server either.

Obviously this is a great help for SSR, e-mail generation, etc.

Actually if I comment out https://github.com/gadicc/meteor-blaze-react-component/blob/master/test-app/server/main.spec.js#L17-L30 and replace it with import './body.html', we get SSR of Blaze templates via React (sorry :)).

I imagine flowrouter-ssr could also add this since they explicitly state that the only reason they don't do it is because Blaze templates aren't available on the server.

dgreensp and others added 30 commits August 10, 2015 22:10
Tried to get everything to an rc.0 of the very latest version,
which required some research in some cases about the published
versions.  For example, some packages had version histories like:

```
...
  1.0.3-winr.2               January 20th, 2015
  1.0.3-winr.3               February 24th, 2015   installed
  1.0.3                      March 17th, 2015      installed
  1.0.4-anubhav.0            August 6th, 2015
  1.0.4-plugins.0            July 22nd, 2015
  1.0.5-galaxy.0             July 17th, 2015
```

In this case, I would bump the version from `1.0.4-plugins.0`
to `1.0.5-rc.0`, skipping `1.0.4`.
Tried to get everything to an rc.0 of the very latest version,
which required some research in some cases about the published
versions.  For example, some packages had version histories like:

```
...
  1.0.3-winr.2               January 20th, 2015
  1.0.3-winr.3               February 24th, 2015   installed
  1.0.3                      March 17th, 2015      installed
  1.0.4-anubhav.0            August 6th, 2015
  1.0.4-plugins.0            July 22nd, 2015
  1.0.5-galaxy.0             July 17th, 2015
```

In this case, I would bump the version from `1.0.4-plugins.0`
to `1.0.5-rc.0`, skipping `1.0.4`.
Tried to get everything to an rc.0 of the very latest version,
which required some research in some cases about the published
versions.  For example, some packages had version histories like:

```
...
  1.0.3-winr.2               January 20th, 2015
  1.0.3-winr.3               February 24th, 2015   installed
  1.0.3                      March 17th, 2015      installed
  1.0.4-anubhav.0            August 6th, 2015
  1.0.4-plugins.0            July 22nd, 2015
  1.0.5-galaxy.0             July 17th, 2015
```

In this case, I would bump the version from `1.0.4-plugins.0`
to `1.0.5-rc.0`, skipping `1.0.4`.
Tried to get everything to an rc.0 of the very latest version,
which required some research in some cases about the published
versions.  For example, some packages had version histories like:

```
...
  1.0.3-winr.2               January 20th, 2015
  1.0.3-winr.3               February 24th, 2015   installed
  1.0.3                      March 17th, 2015      installed
  1.0.4-anubhav.0            August 6th, 2015
  1.0.4-plugins.0            July 22nd, 2015
  1.0.5-galaxy.0             July 17th, 2015
```

In this case, I would bump the version from `1.0.4-plugins.0`
to `1.0.5-rc.0`, skipping `1.0.4`.
Tried to get everything to an rc.0 of the very latest version,
which required some research in some cases about the published
versions.  For example, some packages had version histories like:

```
...
  1.0.3-winr.2               January 20th, 2015
  1.0.3-winr.3               February 24th, 2015   installed
  1.0.3                      March 17th, 2015      installed
  1.0.4-anubhav.0            August 6th, 2015
  1.0.4-plugins.0            July 22nd, 2015
  1.0.5-galaxy.0             July 17th, 2015
```

In this case, I would bump the version from `1.0.4-plugins.0`
to `1.0.5-rc.0`, skipping `1.0.4`.
Tried to get everything to an rc.0 of the very latest version,
which required some research in some cases about the published
versions.  For example, some packages had version histories like:

```
...
  1.0.3-winr.2               January 20th, 2015
  1.0.3-winr.3               February 24th, 2015   installed
  1.0.3                      March 17th, 2015      installed
  1.0.4-anubhav.0            August 6th, 2015
  1.0.4-plugins.0            July 22nd, 2015
  1.0.5-galaxy.0             July 17th, 2015
```

In this case, I would bump the version from `1.0.4-plugins.0`
to `1.0.5-rc.0`, skipping `1.0.4`.
The comments are not related to the fix, they are just for future
reference.

The fix is that having an "own" property named `constructor` should
not disqualify an object from being considered an "instance of some
class."  Instead, we should detect that an object like
`{constructor: ...}` is a plain object by noting that
`!(x instanceof x.constructor)`.
1. Add `addAssets` API to `package.js`
2. Rename `getSourcesFunc` to `getFiles` in internal code
3. Changed `PackageAPI#sources` to `PackageAPI#files` with a new structure that
   has separate objects for assets and sources
4. Added some tests for different error conditions
5. The same file can now be a source and an asset
@gadicc gadicc changed the title Templating compilation on the server (discussion) Template compilation on the server (discussion) Mar 31, 2016
@mitar
Copy link
Contributor

mitar commented Mar 31, 2016

Yes. I have made similar changes in Blaze Components to get them to work on the server side.

There are some issues. Like that if you make <body> or <head> in a template on the server, things break: meteor/meteor#5913

So it is not really possible to create isomorphic templates by default. I had to do some more changes: peerlibrary/meteor-blaze-components@6fd2454

Ideally, <head> and <body> for client target would be ignored (or be added dynamically through JavaScript when it loads), while <head> and <body> on the server target would render it statically to all clients.

@gadicc
Copy link
Author

gadicc commented Apr 1, 2016

Hey, thanks for the quick reply and all the refs. This all looks awesome, so glad you're on this! I'm going to amend my blaze-react-component to work with blaze-components over the weekend and make that the official recommendation (I'll mention the HEAD on server issue, yeah, as per your issue on Meteor, the way it's down is quite weird).

@mitar mitar added this to the Future ideas milestone Apr 17, 2016
@mitar
Copy link
Contributor

mitar commented Apr 17, 2016

I like this idea, but I moved it to "future ideas" on the roadmap because I believe first we need to get Blaze itself into a shape for a stand-alone project. But yes, that would be great to have.

I do see here two steps:

  • getting server-side to render to string
  • getting Meteor to server server-side rendered (Blaze) content on first-load

@gadicc
Copy link
Author

gadicc commented Apr 17, 2016

Yes absolutely, I agree 100%.

I didn't also mention, how happy I am to see Blaze (and related) under your curatorship now... only wish it had happened earlier.

@mitar
Copy link
Contributor

mitar commented Nov 15, 2016

Let's start maybe working on this?

So I think we also need tests to make sure everything works.

@gadicc
Copy link
Author

gadicc commented Nov 15, 2016

@mitar, regrettably - from my side at least - I don't foresee any opportunity to work on this for the remainder of this year. I'm also not using Blaze in any current projects so don't have too much personal incentive in the future either :( - other than a big past love for Blaze!

I hope you and others will be able to move this issue forward. I'm delighted that Blaze is functioning in it's own repo now, in community hands.

@mitar
Copy link
Contributor

mitar commented Nov 17, 2016

We should probably change this as well: https://github.com/meteor/blaze/blob/master/packages/blaze/attrs.js#L251

@mitar
Copy link
Contributor

mitar commented Dec 30, 2016

I cleaned master branch to remove all Meteor history (#112). This means the pull request should be also updated to new history to not base it on old commits. Sorry for this extra work.

@mitar mitar closed this Dec 31, 2016
@mitar mitar reopened this Dec 31, 2016
@mitar
Copy link
Contributor

mitar commented Dec 31, 2016

I am closing this pull request in favor of #223 which describes what should be done. So that maybe somebody else can take this on.

@mitar mitar closed this Dec 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.