-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React Streaming and SSR feature flag (#8764)
- Loading branch information
Showing
7 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/cli/src/commands/experimental/setupStreamingSsr.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers' | ||
|
||
import { getEpilogue } from './util' | ||
|
||
export const command = 'setup-streaming-ssr' | ||
|
||
export const description = | ||
'Enable React Streaming and Server Side Rendering (SSR)' | ||
|
||
export const EXPERIMENTAL_TOPIC_ID = 5052 | ||
|
||
export const builder = (yargs) => { | ||
yargs | ||
.option('force', { | ||
alias: 'f', | ||
default: false, | ||
description: 'Overwrite existing configuration', | ||
type: 'boolean', | ||
}) | ||
.epilogue(getEpilogue(command, description, EXPERIMENTAL_TOPIC_ID, true)) | ||
} | ||
|
||
export const handler = async (options) => { | ||
recordTelemetryAttributes({ | ||
command: ['experimental', command].join(' '), | ||
force: options.force, | ||
}) | ||
const { handler } = await import('./setupStreamingSsrHandler.js') | ||
return handler(options) | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/cli/src/commands/experimental/setupStreamingSsrHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import fs from 'fs' | ||
|
||
import { getConfigPath } from '@redwoodjs/project-config' | ||
|
||
import { writeFile } from '../../lib' | ||
|
||
import { | ||
command, | ||
description, | ||
EXPERIMENTAL_TOPIC_ID, | ||
} from './setupStreamingSsr' | ||
import { printTaskEpilogue } from './util' | ||
|
||
export const handler = async ({ force }) => { | ||
const redwoodTomlPath = getConfigPath() | ||
const configContent = fs.readFileSync(redwoodTomlPath, 'utf-8') | ||
|
||
if (!configContent.includes('[experimental.streamingSsr]')) { | ||
console.log('Adding config to redwood.toml...') | ||
|
||
// Use string replace to preserve comments and formatting | ||
writeFile( | ||
redwoodTomlPath, | ||
configContent.concat(`\n[experimental.streamingSsr]\n enabled = true\n`), | ||
{ | ||
overwriteExisting: true, // redwood.toml always exists | ||
} | ||
) | ||
} else { | ||
if (force) { | ||
console.log('Updating config in redwood.toml...') | ||
writeFile( | ||
redwoodTomlPath, | ||
configContent.replace( | ||
// Enable if it's currently disabled | ||
`\n[experimental.streamingSsr]\n enabled = false\n`, | ||
`\n[experimental.streamingSsr]\n enabled = true\n` | ||
), | ||
{ | ||
overwriteExisting: true, // redwood.toml always exists | ||
} | ||
) | ||
} else { | ||
console.log('Adding config to redwood.toml...') | ||
console.log( | ||
" The [experimental.studio] config block already exists in your 'redwood.toml' file." | ||
) | ||
} | ||
} | ||
|
||
console.log() | ||
|
||
printTaskEpilogue(command, description, EXPERIMENTAL_TOPIC_ID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters