PHPackages                             bear/ssr-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. bear/ssr-module

ActiveLibrary[Framework](/categories/framework)

bear/ssr-module
===============

Javascript SSR module for BEAR.Sunday

2.0.0(3mo ago)2582MITPHPPHP &gt;=8.2.0CI passing

Since May 11Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/bearsunday/BEAR.SsrModule)[ Packagist](https://packagist.org/packages/bear/ssr-module)[ RSS](/packages/bear-ssr-module/feed)WikiDiscussions 2.x Synced 2mo ago

READMEChangelog (4)Dependencies (9)Versions (8)Used By (0)

BEAR.SsrModule
==============

[](#bearssrmodule)

[![CI](https://github.com/bearsunday/BEAR.SsrModule/actions/workflows/ci.yml/badge.svg)](https://github.com/bearsunday/BEAR.SsrModule/actions/workflows/ci.yml)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/54633594876ffaa17d02433ac7a46ccca2a379a4caa74ae8e3c3c832375cad84/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6265617273756e6461792f424541522e5373724d6f64756c652f6261646765732f7175616c6974792d73636f72652e706e673f623d312e78)](https://scrutinizer-ci.com/g/bearsunday/BEAR.SsrModule/?branch=1.x)

JavaScript view layer for BEAR.Sunday

This module enables you to write views in JavaScript while keeping your application logic in PHP. The JavaScript templates are executed server-side (SSR) for initial rendering and can hydrate on the client for interactivity.

When to Use This Module
-----------------------

[](#when-to-use-this-module)

- You want to write views in JavaScript (React, Vue, etc.) within a PHP application
- You prefer to keep server-side application logic in BEAR.Sunday while using JavaScript for UI
- You need both server-side rendering and client-side hydration with the same view code

Prerequisites
-------------

[](#prerequisites)

- PHP 8.2+
- Node.js (for SSR execution)
- [V8Js](http://php.net/v8js) (Optional - for embedded execution without process overhead)

Install
-------

[](#install)

### Composer Install

[](#composer-install)

```
composer require bear/ssr-module
```

### Module Install

[](#module-install)

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

Place your `{app}.bundle.js` file in the `$buildDir` directory. This JS is used for server side rendering (SSR) only.

\#\[Ssr\] Attribute
-------------------

[](#ssr-attribute)

### Basic

[](#basic)

```
use BEAR\SsrModule\Annotation\Ssr;

#[Ssr(app: 'index_ssr')]
public function onGet(): static
{
    $this->body = [
        'name' => 'World',
    ];

    return $this;
}
```

Add the `#[Ssr]` attribute to methods where you want SSR. Set the JS application name with `app`.

### JS Render Application

[](#js-render-application)

Here is a minimalistic JS application. Export a `render` function. Use [koriym/js-ui-skeleton](https://github.com/koriym/Koriym.JsUiSkeleton) to create a JavaScript UI application.

```
const render = state => (
  `Hello ${state.name}`
)
```

### State and Metas

[](#state-and-metas)

In SSR applications, you may need two kinds of data:

- `state`: Public data sent to the client (included in HTML)
- `metas`: Server-side only data

Separate them using the `state` and `metas` parameters in the `#[Ssr]` attribute:

```
use BEAR\SsrModule\Annotation\Ssr;

#[Ssr(app: 'index_ssr', state: ['name', 'age'], metas: ['title'])]
public function onGet(): static
{
    $this->body = [
        'name' => 'World',
        'age' => 4.6E8,
        'title' => 'Age of the World',
    ];

    return $this;
}
```

render.js:

```
const render = (preloadedState, metas) => {
  return `

      ${escape(metas.title)}

      window.__PRELOADED_STATE__ = ${serialize(preloadedState)}

  `;
};
export default render;
```

Cache Modules
-------------

[](#cache-modules)

For production, use cache modules to improve performance:

### APCu Cache

[](#apcu-cache)

```
$this->install(new ApcSsrModule($buildDir));
```

### Custom Cache

[](#custom-cache)

```
use BEAR\SsrModule\Annotation\SsrCacheConfig;
use Psr\SimpleCache\CacheInterface;

// Bind your PSR-16 cache implementation
$this->bind(CacheInterface::class)
    ->annotatedWith(SsrCacheConfig::class)
    ->to(YourCacheImplementation::class);
$this->install(new CacheSsrModule());
$this->install(new SsrModule($buildDir));
```

JavaScript Runtime
------------------

[](#javascript-runtime)

This module uses [koriym/baracoa](https://github.com/koriym/Koriym.Baracoa) for JavaScript execution, which supports two runtimes:

RuntimeProsCons**Node.js** (default)No PHP extension required, easy deploymentProcess spawn overhead per render**V8Js**Embedded execution, no process overheadRequires PHP extension installationNode.js is used automatically when V8Js is not available.

### Performance Note

[](#performance-note)

When using event-driven caching with TTL=0 (cache invalidated by events rather than time), the Node.js process overhead becomes negligible. The rendered HTML is cached indefinitely and invalidated only when the underlying data changes, so JavaScript execution occurs only on cache misses.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance78

Regular maintenance activity

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~794 days

Total

5

Last Release

113d ago

Major Versions

1.x-dev → 2.0.02026-01-22

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

1.x-devPHP &gt;=8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/db4fc75ffc631168d0d7143b6f2c24b1534dfb921212bd851c026c5cbbb1344d?d=identicon)[koriym](/maintainers/koriym)

---

Top Contributors

[![koriym](https://avatars.githubusercontent.com/u/529021?v=4)](https://github.com/koriym "koriym (39 commits)")

---

Tags

bearsundaybearsunday-modulephpreactjsreduxserver-side-renderingv8jsjavascriptreactSSRv8

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bear-ssr-module/health.svg)

```
[![Health](https://phpackages.com/badges/bear-ssr-module/health.svg)](https://phpackages.com/packages/bear-ssr-module)
```

###  Alternatives

[rebing/graphql-laravel

Laravel wrapper for PHP GraphQL

2.2k7.1M26](/packages/rebing-graphql-laravel)[bear/package

BEAR.Sunday application framework package

30527.9k23](/packages/bear-package)[devgeniem/dustpress

WordPress Theme Framework.

5496.8k23](/packages/devgeniem-dustpress)[koriym/baracoa

A JavaScript server side rendering interface

123.9k1](/packages/koriym-baracoa)[tatter/frontend

Opinionated suite of frontend tech for CodeIgniter 4

125.3k](/packages/tatter-frontend)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
