firebase / firebase/firebase-js-sdk

FR: Add Create Bundles Support

Open
#8,354 3 comments 0 reactions 1 assignee Claimed by @wu-hui View on GitHub
api: firestore feature request needs-attention
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### Operating System

n/a

### Browser Version

n/a

### Firebase SDK Version

10.12.3

### Firebase SDK Product:

Firestore

### Describe your project's tooling

Web Frameworks with SSR.

### Describe the problem

Before `FirebaseServerApp` was released, you had to use `firebase-admin-node` on the server. When the data gets hydrated, you would fetch the data twice.

However, since `firebase-admin` has bundle support, you can fetch the data on the server, and load the data to the cache on the browser using:
```ts
await loadBundle(bundle);
```
However, Firebase JS SDK doesn't have a way to create the bundle. Here is an example:
```ts
export const getTodos = async (uid: string) => {

let todoSnapshot: QuerySnap;

try {
todoSnapshot = await adminDB
.collection('todos')
.where('uid', '==', uid)
.orderBy('createdAt')
.get();

} catch (e) {
const fb = e as FirebaseError;
error(500, fb.message);
}

const bundleId = Date.now().toString();

// create buffer as string to pass to client
const todoBuffer = adminDB
.bundle(bundleId)
.add('todo-query', todoSnapshot)
.build()
.toString();

const todos = snapToData(todoSnapshot);

// Here, the todoBuffer is the bundle to be loaded later
return { todos, todoBuffer };
}
```
There should be a way to either:
1. Create the bundle on the server like `firebase-admin-node`
2. Pass the data to the browser to be hydrated preventing you from double fetching

Both of these options would allow caching through a CDN.

### Steps and code to reproduce issue

Currently there are no work arounds without using REST API or `firebase-admin-node`.

The client side is already working with `loadBunde()`, just need a way to create the bundle on the server.

J

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.