Skip to content

SSR

Most SSR logic is handled in our embedded Rust layer. In Rust we spin up a V8 isolate, handle logging, catch and process exceptions, etc. This page only covers the client functions that are exposed to Python.

SSR

mountaineer.ssr.render_ssr

render_ssr(script, render_data, hard_timeout=None)

Render the React component in the provided SSR javascript bundle. This file will be directly executed within the V8 runtime.

To speed up requests for the same exact content (ie. same react and same data) we cache the result of the render_ssr_rust call by default for a limited amount of previous calls. We limit the overall size of this cache to 5MB.

PARAMETER DESCRIPTION
script

The raw code of the javascript bundle to execute. Should be pre-compiled into an SSR compatible package with a single entrypoint.

TYPE: str

render_data

The data to inject into the SSR javascript bundle

TYPE: dict[str, Any]

hard_timeout

The maximum time to allow the render to take in seconds. If the render takes longer than this time, our thread supervisor will kick in and terminate the rust worker.

TYPE: int | float | None DEFAULT: None

RAISES DESCRIPTION
TimeoutError

If the render takes longer than the hard_timeout

V8RuntimeError

If the V8 runtime throws an exception during the render

mountaineer.ssr.V8RuntimeError

Bases: Exception

An exception thrown by the V8 runtime in the case of a permanent failure that involves the content of the script.

Source Maps

mountaineer.js_compiler.source_maps.SourceMapParser

SourceMapParser(path)

Parse sourcemaps according to the official specification: https://sourcemaps.info/spec.html

PARAMETER DESCRIPTION
relative_to

If specified, will output source paths relative to this path.

path instance-attribute

path = Path(path)

source_map instance-attribute

source_map = None

parsed_mappings instance-attribute

parsed_mappings = None

parse

parse()

Parse the source map file and build up the internal mappings. This is deterministic with respect to the initialized source map path, so this will be a no-op if it's already been run.

get_original_location

get_original_location(line, column)

For a compiled line and column, return the original line and column where they appeared in the pre-built file.

PARAMETER DESCRIPTION
line

The line number in the compiled file

TYPE: int

column

The column number in the compiled file

TYPE: int

map_exception

map_exception(exception)

Given a JS stack exception, try to map it to the original files and line numbers

PARAMETER DESCRIPTION
exception

The exception string to map

TYPE: str

RETURNS DESCRIPTION
str

The exception string with the original file and line numbers. Note that some exception stack traces may not be mappable, and will be left as-is.

convert_relative_path

convert_relative_path(absolute_path)

Absolute paths are convenient for internal use since they fully qualify a given file. However, for display they often get long and repetitive across multiple lines. This function will convert an absolute path to a relative path if it's within the same directory as the current working directory.

PARAMETER DESCRIPTION
absolute_path

The absolute path to convert

TYPE: str

RETURNS DESCRIPTION

The relative path if it's within the current working directory, otherwise the unmodified absolute path.