Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 4 additions & 0 deletions packages/react-server/lib/start/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CONFIG_ROOT,
LOGGER_CONTEXT,
SERVER_CONTEXT,
SOURCEMAP_ENABLED,
} from "../../server/symbols.mjs";
import { formatDuration } from "../utils/format.mjs";
import getServerAddresses from "../utils/server-address.mjs";
Expand Down Expand Up @@ -45,6 +46,9 @@ async function worker(root, options, config) {

await runtime_init$(async () => {
runtime$(CONFIG_CONTEXT, config);
// Check if sourcemaps are available by looking for .map files in build output
// This will be set to true if sourcemaps were generated during build
runtime$(SOURCEMAP_ENABLED, false);
const logger = await createLogger(configRoot);
const server = await createServer(root, options);
const { port, listenerHost } = getServerConfig(configRoot, options);
Expand Down
21 changes: 21 additions & 0 deletions packages/react-server/lib/start/ssr-handler.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { access, constants as fsConstants } from "node:fs/promises";
import { createRequire, register } from "node:module";
import { join, relative } from "node:path";
import { pathToFileURL } from "node:url";
Expand Down Expand Up @@ -38,6 +39,7 @@ import {
RENDER_CONTEXT,
RENDER_STREAM,
SERVER_CONTEXT,
SOURCEMAP_ENABLED,
STYLES_CONTEXT,
} from "../../server/symbols.mjs";
import { ContextManager } from "../async-local-storage.mjs";
Expand Down Expand Up @@ -109,6 +111,25 @@ export default async function ssrHandler(root, options = {}) {
const moduleCacheStorage = new ContextManager();
await module_loader_init$(moduleLoader, moduleCacheStorage);

// Check if sourcemaps are available by checking if entryModule has a .map file
let sourcemapEnabled = false;
try {
await access(`${entryModule}.map`, fsConstants.R_OK);
sourcemapEnabled = true;
// Dynamically import and install source-map-support only when source maps are available
const { default: sourceMapSupport } = await import("source-map-support");
sourceMapSupport.install({
environment: "node",
hookRequire: false,
handleUncaughtExceptions: false,
});
console.log("[SourceMap] Source map support enabled");
} catch {
// Sourcemaps not available
console.log("[SourceMap] No source maps found");
}
runtime$(SOURCEMAP_ENABLED, sourcemapEnabled);

const importMap =
configRoot.importMap || configRoot.resolve?.shared
? {
Expand Down
1 change: 1 addition & 0 deletions packages/react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"socket.io": "^4.8.1",
"socket.io-client": "^4.8.1",
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
"strip-ansi": "^7.1.0",
"style-to-js": "^1.1.12",
"unstorage": "^1.16.0",
Expand Down
1 change: 1 addition & 0 deletions packages/react-server/server/symbols.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const SSR_CONTROLLER = Symbol.for("SSR_CONTROLLER");
export const ROUTE_MATCH = Symbol.for("ROUTE_MATCH");
export const STYLES_CONTEXT = Symbol.for("STYLES_CONTEXT");
export const BUILD_OPTIONS = Symbol.for("BUILD_OPTIONS");
export const SOURCEMAP_ENABLED = Symbol.for("SOURCEMAP_ENABLED");
export const ACTION_CONTEXT = Symbol.for("ACTION_CONTEXT");
export const RELOAD = Symbol.for("RELOAD");
export const RENDER = Symbol.for("RENDER");
Expand Down
Loading
Loading