---
title: "フレームワーク連携と SSR"
description: "React、Vue、Svelte で共通のウィジェットを使い、初期スレッドをサーバーで描画します。"
---

> Documentation Index
> Fetch the complete documentation index at: https://blua.pwp.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# フレームワーク連携と SSR

## SDK をインストールする

Blua のリポジトリでパッケージを作成します。生成された `.tgz` を利用側のプロジェクトへコピーしてインストールしてください。二つ目のコマンドは `vendor` ディレクトリにコピーした場合の例です。

```sh
pnpm sdk:pack
```

`packages/embed/dist/blua-embed-0.0.0.tgz`

```sh
pnpm add ./vendor/blua-embed-0.0.0.tgz
```

## React

```tsx
import { BluaComments } from '@blua/embed/react';

export function Discussion({ slug }: { slug: string }) {
  return (
    <BluaComments endpoint="https://blua.example" siteKey="garden" pageKey={slug} locale="ja" />
  );
}
```

## Vue

```vue
<script setup lang="ts">
import { BluaComments } from '@blua/embed/vue';
defineProps<{ slug: string }>();
</script>

<template>
  <BluaComments endpoint="https://blua.example" site-key="garden" :page-key="slug" locale="ja" />
</template>
```

## Svelte

```svelte
<script lang="ts">
  import BluaComments from '@blua/embed/svelte';
  let { slug }: { slug: string } = $props();
</script>

<BluaComments endpoint="https://blua.example" siteKey="garden" pageKey={slug} locale="ja" />
```

## SSR

サーバー側で公開用の bootstrap を取得し、アダプターの `bootstrap` プロパティに渡します。初期 HTML にコメント一覧が含まれ、ブラウザーでもそのデータを引き継ぎます。HTML を直接返すテンプレートでは次の関数を使えます。

```ts
import { createBluaApiClient, renderBluaCommentsSsr } from '@blua/embed';

export async function renderDiscussion(slug: string) {
  const props = { endpoint: 'https://blua.example', siteKey: 'garden', pageKey: slug };
  const bootstrap = await createBluaApiClient(props).bootstrap('newest');
  return renderBluaCommentsSsr({ ...props, bootstrap, locale: 'ja' });
}
```

操作を有効にするにはページで `embed.js` を読み込みます。共有キャッシュに含めるのは公開済みのコメントのみです。投稿者だけが閲覧できる審査待ち投稿、セッション、サイト資格情報は非公開の応答に限定してください。

Source: https://blua.pwp.sh/docs/ja/embed/frameworks/
