Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

* Fixed issue where apps run in Workbench were unexpectedly crashing. Apps running in Workbench will now have `ws_per_message_deflate=False` enforced. (#2005)

* Fixed an issue where the `<main>` areas of `ui.page_sidebar()` and `ui.page_navbar()` (with a `sidebar`) were made to be a fillable containers even when `fillable=False`. (#1816)

* Fixed an issue where the `.update_user_input()` method on `ui.Chat()` isn't working in shinylive. (#1891)
Expand Down
16 changes: 16 additions & 0 deletions shiny/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import sys
import types
import warnings
from pathlib import Path
from typing import Any, Optional

Expand All @@ -20,6 +21,7 @@

from . import __version__, _autoreload, _hostenv, _static, _utils
from ._docstring import no_example
from ._hostenv import is_workbench
from ._typing_extensions import NotRequired, TypedDict
from .bookmark._bookmark_state import shiny_bookmarks_folder_name
from .express import is_express_app
Expand Down Expand Up @@ -399,6 +401,8 @@ def run_app(

maybe_setup_rsw_proxying(log_config)

_set_workbench_kwargs(kwargs)

uvicorn.run( # pyright: ignore[reportUnknownMemberType]
app,
host=host,
Expand Down Expand Up @@ -713,6 +717,18 @@ class ReloadArgs(TypedDict):
reload_dirs: NotRequired[list[str]]


def _set_workbench_kwargs(kwargs: dict[str, Any]) -> None:
if is_workbench():
if kwargs.get("ws_per_message_deflate"):
# Workaround for nginx/uvicorn issue within Workbench
# https://github.com/rstudio/rstudio-pro/issues/7368#issuecomment-2918016088
warnings.warn(
"Overwriting kwarg `ws_per_message_deflate=True` to `False` to avoid breaking issue in Workbench",
stacklevel=2,
)
kwargs["ws_per_message_deflate"] = False


# Check that the version of rsconnect supports Shiny Express; can be removed in the
# future once this version of rsconnect is widely used. The dependency on "packaging"
# can also be removed then, because it is only used here. (Added 2024-03)
Expand Down
55 changes: 55 additions & 0 deletions tests/pytest/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import warnings
from typing import Any, Dict

import pytest

from shiny._main import _set_workbench_kwargs


def test_workbench_kwargs_if_url_set():
"""
Test that the `ws_per_message_deflate` kwarg is set to False when
RS_SERVER_URL and RS_SESSION_URL are set in the environment.
This is to avoid breaking issues in Workbench.
If the kwargs are set to True, a warning is raised and the value is set to False.
"""
# Workbench URL is set, kwargs are not
os.environ["RS_SERVER_URL"] = "any_string"
os.environ["RS_SESSION_URL"] = "any_string"

kwargs: Dict[str, Any] = {}
_set_workbench_kwargs(kwargs)
assert kwargs.get("ws_per_message_deflate") is False

# kwarg have been set to True
kwargs = {
"ws_per_message_deflate": True,
}
with pytest.warns(UserWarning):
warnings.warn(
"Overwriting kwarg `ws_per_message_deflate=True` to `False` to avoid breaking issue in Workbench",
UserWarning,
stacklevel=2,
)
_set_workbench_kwargs(kwargs)
assert kwargs.get("ws_per_message_deflate") is False

# Teardown
del os.environ["RS_SERVER_URL"]
del os.environ["RS_SESSION_URL"]


def test_workbench_kwargs_if_url_not_set():
"""
Test that the `ws_per_message_deflate` kwarg is not changed if the RS_SERVER_URL and RS_SESSION_URL environment variables are not set.
"""
kwargs: Dict[str, Any] = {
"ws_per_message_deflate": True,
}
_set_workbench_kwargs(kwargs)
assert kwargs.get("ws_per_message_deflate") is True

kwargs: Dict[str, Any] = {}
_set_workbench_kwargs(kwargs)
assert kwargs.get("ws_per_message_deflate") is None
Loading