Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Offer a renderSync method? #48

Closed
zachleat opened this issue Nov 29, 2017 · 8 comments
Closed

Offer a renderSync method? #48

zachleat opened this issue Nov 29, 2017 · 8 comments

Comments

@zachleat
Copy link
Contributor

Most templating engines offer synchronous render methods (ejs, mustache, handlebars, haml, pug, nunjucks, etc).

Does one exist for liquidjs? If not, could one be added?

(love this library btw—thank you)

@harttle
Copy link
Owner

harttle commented Nov 29, 2017

Maybe not possible in current code base. We know async methods cannot be converted to sync. So we made intensive discussion over whether to support async in #3 .

Nevertheless, supporting sync render methods without regression would be great. Welcome to propose a solution for this issue.

@harttle
Copy link
Owner

harttle commented Nov 30, 2017

Render could be implemented syncly, while the only reason to be async is Async Tags. Especially {%include%} and {%layout%}, and things like one could do some database manipulation during tag/filter rendering.

@zachleat
Copy link
Contributor Author

Interesting! To be frank I think I’d be happy with throwing an error if the template has an async tag and rendering is in sync mode.

@zachleat
Copy link
Contributor Author

zachleat commented Dec 4, 2017

I worked around this in my upstream code so it isn’t necessary for me any more! It may be useful for someone else in the future but I would consider it low priority. In fact, other libs might tend towards what you’ve done instead 😎 Thanks for the discussion!

@zachleat zachleat closed this as completed Dec 4, 2017
@harttle harttle mentioned this issue Mar 1, 2019
@harttle
Copy link
Owner

harttle commented Jun 13, 2019

Now we use TypeScript and I'll try make it support both async and sync calls, maybe generate additional code during rollup build.

@harttle harttle reopened this Jun 13, 2019
@harttle harttle added this to the 9.0.0 milestone Jun 26, 2019
harttle pushed a commit that referenced this issue Aug 26, 2019
# [9.0.0](v8.5.3...v9.0.0) (2019-08-26)

### Bug Fixes

* break/continue omitting output before them, [#123](#123) ([ae45c46](ae45c46))
* reactjs demo during yarn install, fixes [#145](#145) ([b65df44](b65df44))

### Code Refactoring

* return value of Tag#render is no longer used ([8028f82](8028f82))

### Features

* renderSync, parseAndRenderSync and renderFileSync, see [#48](#48) ([7fb01ad](7fb01ad))

### Performance Improvements

* target to es6, fixes [#137](#137) ([3b9fc7e](3b9fc7e))

### BREAKING CHANGES

* Tag#render now returns void, use emitter argument
to write rendered html.
* ship to Node.js 8, the dist/liquid.cjs.js (main) nolonger
supports Node.js 6, other bundles are also provided via dist/liquid.esm.js, dist/liquid.js (ES5 umd) and liquid.min.js (minified ES5 umd)
* remove default export, now should be used like import
{Liquid} from 'liquidjs'
@harttle
Copy link
Owner

harttle commented Aug 26, 2019

renderFileSync, renderSync, parseAndRenderSync are now supported by v9.0.0, but with some breaking changes. Feel free to file an issue if there's problem during upgrade. Closing, hope it helps!

@harttle harttle closed this as completed Aug 26, 2019
@Munawwar
Copy link

Munawwar commented Sep 3, 2019

Ok I did a simple test of renderSync() and seems to be working. Integrated liquidjs with SahteReact (front-end library I was building for Shopify stores... so now, one can reuse shopify templates on the client-side co-existing with libraries like jquery!)

Munawwar/SahteReact@3251a21

@harttle how to include partials on browser (without async fetching)? how to use dynamicPartials?

@harttle
Copy link
Owner

harttle commented Sep 3, 2019

By default, it's implemented as sync xhr which is absolutely bad practice. see:

function readFileSync (url: string): string {

A customed, platform-related fs can be specified in the LiquidOptions, as discussed in #131

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants