Skip to content

Commit 8a5d34f

Browse files
committed
refactor(nuxt): types, ssr
1 parent 88a0f7d commit 8a5d34f

File tree

9 files changed

+112
-18
lines changed

9 files changed

+112
-18
lines changed

packages/nuxt/.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"comma-dangle": [
1616
"error",
1717
"always-multiline"
18-
]
18+
],
19+
"vue/require-v-for-key": "off",
1920
}
2021
}

packages/nuxt/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"require": "./dist/module.cjs"
1111
}
1212
},
13-
"main": "./dist/module.cjs",
13+
"main": "./dist/module.mjs",
1414
"types": "./dist/types.d.ts",
1515
"files": [
1616
"dist"
@@ -27,16 +27,16 @@
2727
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground"
2828
},
2929
"dependencies": {
30-
"@nuxt/kit": "3.0.0-rc.13"
30+
"@nuxt/kit": "^3.0.0-rc.13"
3131
},
3232
"devDependencies": {
3333
"@firebase/app-types": "^0.8.1",
3434
"@nuxt/module-builder": "^0.2.0",
35-
"@nuxt/schema": "3.0.0-rc.13",
35+
"@nuxt/schema": "^3.0.0-rc.13",
3636
"@nuxtjs/eslint-config-typescript": "^11.0.0",
3737
"eslint": "^8.27.0",
3838
"firebase": "^9.14.0",
39-
"nuxt": "^3.0.0-rc.12",
39+
"nuxt": "^^3.0.0-rc.12",
4040
"vuefire": "workspace:*"
4141
}
4242
}

packages/nuxt/playground/pages/database/index.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const router = useRouter()
33
44
const routes = router
55
.getRoutes()
6-
.filter((record) => record.path.startsWith('/database/'))
6+
.filter(record => record.path.startsWith('/database/'))
77
.map((record) => {
88
return {
99
name: record.name,
@@ -14,10 +14,14 @@ const routes = router
1414

1515
<template>
1616
<div>
17-
<NuxtLink to="/">&lt;&lt; Back Home</NuxtLink>
17+
<NuxtLink to="/">
18+
&lt;&lt; Back Home
19+
</NuxtLink>
1820
<ul>
1921
<li v-for="link in routes">
20-
<NuxtLink :to="link">{{ link.path }}</NuxtLink>
22+
<NuxtLink :to="link">
23+
{{ link.path }}
24+
</NuxtLink>
2125
</li>
2226
</ul>
2327
</div>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script setup lang="ts">
2+
import { doc, getDoc } from 'firebase/firestore'
3+
import { useDocument, useFirestore, usePendingPromises } from 'vuefire'
4+
import { ref } from 'vue'
5+
6+
const db = useFirestore()
7+
const configRef = doc(db, 'configs', 'jORwjIykFo2NmkdzTkhU')
8+
// const itemRef = doc(db, 'tests', 'item')
9+
const isDoneFetching = ref(false)
10+
const isAllDoneFetching = ref(false)
11+
12+
getDoc(configRef).then((data) => {
13+
console.log('got data once', data)
14+
})
15+
16+
const { data: config, promise } = useDocument(configRef, { wait: true })
17+
// const { data: hey } = useDocument(configRef)
18+
19+
promise.value.then((data) => {
20+
console.log('one', data)
21+
isDoneFetching.value = true
22+
})
23+
24+
usePendingPromises().then((data) => {
25+
console.log(data)
26+
isAllDoneFetching.value = true
27+
})
28+
</script>
29+
30+
<template>
31+
<div>
32+
<p>config:</p>
33+
<p>finished: {{ isDoneFetching }}</p>
34+
<p>All finished: {{ isAllDoneFetching }}</p>
35+
<pre>{{ config }}</pre>
36+
</div>
37+
</template>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script lang="ts" setup>
2+
const router = useRouter()
3+
4+
const routes = router
5+
.getRoutes()
6+
.filter(record => record.path.startsWith('/firestore/'))
7+
.map((record) => {
8+
return {
9+
name: record.name,
10+
path: record.path,
11+
}
12+
})
13+
</script>
14+
15+
<template>
16+
<div>
17+
<NuxtLink to="/">
18+
&lt;&lt; Back Home
19+
</NuxtLink>
20+
<ul>
21+
<li v-for="link in routes">
22+
<NuxtLink :to="link">
23+
{{ link.path }}
24+
</NuxtLink>
25+
</li>
26+
</ul>
27+
</div>
28+
</template>

packages/nuxt/playground/pages/index.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
<div>
33
<ul>
44
<li>
5-
<NuxtLink to="/database">Database</NuxtLink>
5+
<NuxtLink to="/database">
6+
Database
7+
</NuxtLink>
8+
</li>
9+
<li>
10+
<NuxtLink to="/firestore">
11+
Firestore
12+
</NuxtLink>
613
</li>
714
</ul>
815
</div>

packages/nuxt/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fileURLToPath } from 'node:url'
22
import { resolve } from 'path'
33
import { addPlugin, defineNuxtModule } from '@nuxt/kit'
4-
import { FirebaseOptions } from '@firebase/app-types'
4+
import { type FirebaseOptions } from '@firebase/app-types'
55

66
export interface VueFireNuxtModuleOptions {
77
optionsApiPlugin: boolean

packages/nuxt/src/runtime/plugin.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
import { defineNuxtPlugin } from '#app'
1+
import { usePendingPromises, VueFire, useSSRInitialState } from 'vuefire'
2+
import { initializeApp } from 'firebase/app'
3+
import { defineNuxtPlugin } from '#imports'
24

35
export default defineNuxtPlugin(async (nuxtApp) => {
4-
// TODO: create the plugin that stores the promises with data
6+
// TODO: initialize firebase app from config
7+
const firebaseApp = initializeApp()
58

6-
if (process.server) {
7-
await 2 // TODO: wait for promises to resolve
9+
nuxtApp.vueApp.use(
10+
// @ts-expect-error: nuxt type bug?
11+
VueFire,
12+
{
13+
firebaseApp,
14+
}
15+
)
816

9-
// nuxtApp.payload.firebaseState = ...
10-
} else {
11-
// hydrate the plugin state from nuxtApp.payload.firebaseState
17+
if (process.server) {
18+
await usePendingPromises()
19+
// TODO: pass the firebaseApp
20+
nuxtApp.payload.vuefire = useSSRInitialState()
21+
} else if (nuxtApp.payload?.vuefire) {
22+
// hydrate the plugin state from nuxtApp.payload.vuefire
23+
useSSRInitialState(nuxtApp.payload.vuefire)
1224
}
1325

1426
return {

packages/nuxt/tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"extends": "./playground/.nuxt/tsconfig.json"
2+
"extends": "./playground/.nuxt/tsconfig.json",
3+
"include": [
4+
// missing in the playground
5+
"./src"
6+
, "./playground"
7+
]
38
}

0 commit comments

Comments
 (0)