Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-apps) - fix old react apps to support hot reload when using port forwarding #9091

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scopes/react/react/apps/web/react.application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { html } from '../../webpack';
import { ReactDeployContext } from './deploy-context';
import { computeResults } from './compute-results';
import { clientConfig, ssrConfig, calcOutputPath, ssrBuildConfig, buildConfig } from './webpack/webpack.app.ssr.config';
import { addDevServer, setOutput, replaceTerserPlugin } from './webpack/mutators';
import { addDevServer, setOutput, replaceTerserPlugin, setDevServerClient } from './webpack/mutators';
import { createExpressSsr, loadSsrApp, parseAssets } from './ssr/ssr-express';

export class ReactApp implements Application {
Expand Down Expand Up @@ -60,7 +60,7 @@ export class ReactApp implements Application {
const devServerContext = await this.getDevServerContext(context);
const devServer = this.reactEnv.getDevServer(
devServerContext,
[addDevServer, setOutput, ...this.transformers],
[addDevServer, setOutput, setDevServerClient, ...this.transformers],
this.webpackModulePath,
this.webpackDevServerModulePath
);
Expand Down
18 changes: 18 additions & 0 deletions scopes/react/react/apps/web/webpack/mutators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ export function setOutput(configMutator: WebpackConfigMutator) {
return configMutator;
}

/**
* Setting the webSocketURL to use port 0
* This is will make the dev server to use the same port as the website
* This is mainly required for a cases when the port is forwarded to a different port
* For example when using online vscode instances
* @param configMutator
* @returns
*/
export function setDevServerClient(configMutator: WebpackConfigMutator) {
if (!configMutator.raw.devServer) configMutator.raw.devServer = {};

configMutator.raw.devServer.client = {
webSocketURL: 'ws://0.0.0.0:0/ws',
};

return configMutator;
}

export function replaceTerserPlugin({ prerender = false }: { prerender: boolean }) {
return (configMutator: WebpackConfigMutator) => {
if (!configMutator.raw.optimization?.minimizer) return configMutator;
Expand Down