Javascript SSR module for BEAR.Sunday

1.0.1 2017-10-12 07:42 UTC

This package is auto-updated.

Last update: 2022-06-09 08:50:46 UTC


Scrutinizer Code Quality Code Coverage Build Status

JavaScript server side rendering (SSR) module interface for BEAR.Sunday


  • php7.1
  • V8Js (Optional)


Composer Install

composer require bear/ssr-module

Module Install

$buildDir = dirname(__DIR__, 2) . '/var/www/build';
$this->install(new SsrModule($buildDir, 'index_ssr');

In this canse, you need to place index_ssr.bundle.js file at $baseDir directory. This JS is used server side rendring (SSR) only.

@Ssr Annotation


 * @Ssr(app="index_ssr")
public function onGet()
    $this->body = [
        'name' => 'World'

    return $this;

Annotate @Ssr at the method where you want to SSR. Set JS application name to app.

JS Render Application

Here is a very minimalistic JS application. Export render function to render. Use koriym/js-ui-skeletom to create Javascript UI application.

const render = state => (
  `Hello ${}`

State and metas

In SSR application, you sometime want to deal two kind of data. One is for client side which means you are OK to be a public in HTML. One is server side only.

You can separate state and meta data by custom attribute in @Ssr annotation. metas are only used in server side.

 * @Ssr(
 *   app="index_ssr",
 *   state={"name", "age"},
 *   meta={"title"}
 * )
public function onGet()
    $this->body = [
        'name' => 'World',
        'age' => 4.6E8;
        'title' => 'Age of the World'

    return $this;


const render = (preloadedState, metas) => {
      <script>window.__PRELOADED_STATE__ = ${serialize(preloadedState)}</script>
export default render;