Skip to content

Commit

Permalink
fix(realtime): update logic for including sseLink (#10025)
Browse files Browse the repository at this point in the history
Since realtime went out of experimental, the logic for including the SSE
Link in the bundle needs to be updated. We can't just use TOML config
anymore as a tell since there's none. Right now all I can think of as a
real source of truth is if the user has the realtime package on the api
side.
  • Loading branch information
jtoar committed Feb 16, 2024
1 parent 903f8d4 commit 7fc0648
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from 'fs'
import fs from 'fs'
import path from 'path'

import react from '@vitejs/plugin-react'
Expand Down Expand Up @@ -30,6 +30,12 @@ export default function redwoodPluginVite(): PluginOption[] {

const relativeEntryPath = path.relative(rwPaths.web.src, clientEntryPath)

// If realtime is enabled, we want to include the sseLink in the bundle.
// Right now the only way we have of telling is if the package is installed on the api side.
const realtimeEnabled = fs
.readFileSync(path.join(rwPaths.api.base, 'package.json'), 'utf-8')
.includes('@redwoodjs/realtime')

return [
{
name: 'redwood-plugin-vite-html-env',
Expand Down Expand Up @@ -83,7 +89,7 @@ export default function redwoodPluginVite(): PluginOption[] {
// So we inject the entrypoint with the correct extension .tsx vs .jsx

// And then inject the entry
if (existsSync(clientEntryPath)) {
if (fs.existsSync(clientEntryPath)) {
return html.replace(
'</head>',
// @NOTE the slash in front, for windows compatibility and for pages in subdirectories
Expand All @@ -99,7 +105,7 @@ export default function redwoodPluginVite(): PluginOption[] {
// but note index.html does not come through as an id during dev
transform: (code: string, id: string) => {
if (
existsSync(clientEntryPath) &&
fs.existsSync(clientEntryPath) &&
normalizePath(id) === normalizePath(rwPaths.web.html)
) {
return {
Expand Down Expand Up @@ -286,7 +292,7 @@ export default function redwoodPluginVite(): PluginOption[] {
id: /@redwoodjs\/router\/dist\/splash-page/,
},
]),
!rwConfig.experimental.realtime.enabled &&
!realtimeEnabled &&
removeFromBundle([
{
id: /@redwoodjs\/web\/dist\/apollo\/sseLink/,
Expand Down

0 comments on commit 7fc0648

Please sign in to comment.