Skip to content

Commit 4347864

Browse files
committed
Switch docs islands to vue-vapor and fix build issues
Convert DarkModeSwitch and TimeAgo (the two Vue islands in the docs site) to .vapor.vue format. These are the only components that use client: directives with <script setup>, making them candidates for Vue Vapor's lighter runtime. Changes required to make the build succeed: - Add explicit imports in TheNavBar.vue and LastUpdated.vue since unplugin-vue-components derives "DarkModeSwitchVapor" from the .vapor.vue filename rather than "DarkModeSwitch" - Create vapor-shim.ts that maps createVaporApp to createApp for Vue 3.5.x compatibility (removable when Vue 3.6+ is installed) - Add vue/vapor alias pointing to the shim - Fix chunkForSpecialExtension scoping bug in chunks.ts (was not passed to vendorPerFramework recursive calls) - Add vapor-shim to hydration package build entries and exports - Convert TimeAgo's $ref/$computed macros to standard ref()/computed() since Reactivity Transform may not work with Vapor compilation https://claude.ai/code/session_01Rn1bhLJcwHBfA2ewWEyWWE
1 parent a996cf4 commit 4347864

9 files changed

Lines changed: 29 additions & 9 deletions

File tree

File renamed without changes.

docs/src/components/LastUpdated.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<script setup lang="ts">
2+
import TimeAgo from './TimeAgo.vapor.vue'
3+
</script>
4+
15
<template>
26
<p v-if="$meta.lastUpdated" class="text-sm">
37
<span class="inline-block font-medium">Last Updated:</span>

docs/src/components/TheNavBar.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<script setup lang="ts">
2+
import DarkModeSwitch from './DarkModeSwitch.vapor.vue'
3+
</script>
4+
15
<template>
26
<header class="nav-bar bg-html flex items-center border-b">
37
<div class="flex flex-1 h-full container !max-w-screen-2xl mx-auto px-3 md:px-6">
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
2-
import { watch, onBeforeUnmount } from 'vue'
2+
import { ref, computed, watch, onBeforeUnmount } from 'vue'
33
44
const { date } = defineProps<{ date: Date }>()
55
6-
let relativeTimeStr = $ref('')
7-
let dateStr = $computed(() => date.toLocaleDateString('en-US', { day: 'numeric', month: 'long', year: 'numeric' }))
8-
let timeStr = $computed(() => date.toISOString())
6+
const relativeTimeStr = ref('')
7+
const dateStr = computed(() => date.toLocaleDateString('en-US', { day: 'numeric', month: 'long', year: 'numeric' }))
8+
const timeStr = computed(() => date.toISOString())
99
1010
if (!import.meta.env.SSR) {
1111
const currentTime = (hoursAgo: number): string => {
@@ -19,10 +19,10 @@ if (!import.meta.env.SSR) {
1919
}
2020
2121
const updateRelativeTimeStr = () => {
22-
relativeTimeStr = currentTime((Number(new Date()) - Number(date)) / (60 * 60 * 1000))
22+
relativeTimeStr.value = currentTime((Number(new Date()) - Number(date)) / (60 * 60 * 1000))
2323
}
2424
25-
let activeInterval = setInterval(updateRelativeTimeStr, 60 * 1000)
25+
const activeInterval = setInterval(updateRelativeTimeStr, 60 * 1000)
2626
onBeforeUnmount(() => clearInterval(activeInterval))
2727
watch(() => date, updateRelativeTimeStr, { immediate: true })
2828
}

packages/hydration/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"./vanilla": "./dist/vanilla.js",
2929
"./vue": "./dist/vue.js",
3030
"./vue-vapor": "./dist/vue-vapor.js",
31+
"./vapor-shim": "./dist/vapor-shim.js",
3132
"./dist/*": "./dist/*",
3233
"./package.json": "./package.json"
3334
},

packages/hydration/vapor-shim.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Compatibility shim for vue/vapor until Vue 3.6+ is available.
2+
// Maps createVaporApp to createApp so that the vue-vapor adapter works
3+
// with Vue 3.5.x. When Vue 3.6+ is installed (which exports vue/vapor
4+
// natively), this shim can be removed along with its alias.
5+
export { createApp as createVaporApp } from 'vue'

packages/hydration/vite.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
},
99
},
1010
pack: {
11-
entry: ['hydration.ts', 'preact.ts', 'vue.ts', 'vanilla.ts', 'solid.ts', 'svelte.ts'],
11+
entry: ['hydration.ts', 'preact.ts', 'vue.ts', 'vue-vapor.ts', 'vapor-shim.ts', 'vanilla.ts', 'solid.ts', 'svelte.ts'],
1212
platform: 'browser',
1313
dts: true,
1414
deps: {

packages/iles/src/node/alias.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export function resolveAliases (root: string, userConfig: UserConfig): AliasOpti
6868
'@vue/runtime-dom/dist/runtime-dom.esm-bundler.js',
6969
),
7070
},
71+
// Shim for vue/vapor until Vue 3.6+ is available.
72+
{
73+
find: /^vue\/vapor$/,
74+
replacement: require.resolve('@islands/hydration/vapor-shim'),
75+
},
7176
{
7277
find: /^vue-router$/,
7378
replacement: require.resolve(

packages/iles/src/node/build/chunks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function extendManualChunks (config: AppConfig): GetManualChunk {
2626
if (id.includes('hydration/dist')) return 'iles'
2727
const name = userChunks?.(id, api)
2828
if (name) return name
29-
if (id.includes('node_modules')) return vendorPerFramework(chunkForExtension, id, api, cache)
29+
if (id.includes('node_modules')) return vendorPerFramework(chunkForExtension, chunkForSpecialExtension, id, api, cache)
3030
}
3131
}
3232

@@ -36,6 +36,7 @@ export function extendManualChunks (config: AppConfig): GetManualChunk {
3636
// shared chunk which would delay hydration for all islands.
3737
function vendorPerFramework (
3838
chunkForExtension: Record<string, string>,
39+
chunkForSpecialExtension: Record<string, string>,
3940
id: string,
4041
api: ManualChunkMeta,
4142
cache: Map<string, string | undefined>,
@@ -67,7 +68,7 @@ function vendorPerFramework (
6768

6869
let name
6970
for (const importer of mod.importers) {
70-
const importerChunk = vendorPerFramework(chunkForExtension, importer, api, cache, importStack.concat(id))
71+
const importerChunk = vendorPerFramework(chunkForExtension, chunkForSpecialExtension, importer, api, cache, importStack.concat(id))
7172
if (!name) name = importerChunk
7273
if (importerChunk && importerChunk !== name) break
7374
}

0 commit comments

Comments
 (0)