Skip to content

Commit be0afb1

Browse files
authored
Share button on notebook no longer uses the current base url for web viewer urls (#11379)
1 parent 7668141 commit be0afb1

File tree

5 files changed

+51
-38
lines changed

5 files changed

+51
-38
lines changed

crates/top/rerun/src/commands/entrypoint.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,7 @@ fn native_startup_options_from_args(args: &Args) -> anyhow::Result<re_viewer::St
984984
force_wgpu_backend: args.renderer.clone(),
985985
video_decoder_hw_acceleration,
986986

987-
on_event: None,
988-
989-
panel_state_overrides: Default::default(),
987+
..Default::default()
990988
})
991989
}
992990

crates/viewer/re_viewer/src/startup_options.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ pub struct StartupOptions {
8080
pub enable_history: bool,
8181

8282
/// The base viewer url that's used when sharing a link in this viewer.
83-
#[cfg(target_arch = "wasm32")]
84-
pub viewer_url: Option<String>,
83+
///
84+
/// If not set:
85+
/// * notebooks & native: use rerun.io/viewer with the crate's last known stable version
86+
/// * web viewers: use the url of the page it is embedded in
87+
pub viewer_base_url: Option<String>,
8588
}
8689

8790
impl StartupOptions {
@@ -102,20 +105,28 @@ impl StartupOptions {
102105
/// The url to use for the web viewer when sharing links.
103106
#[allow(clippy::unused_self)] // Only used on web.
104107
pub fn web_viewer_base_url(&self) -> Option<url::Url> {
105-
#[cfg(target_arch = "wasm32")]
106-
{
107-
self.viewer_url
108-
.as_ref()
109-
.and_then(|url| url.parse().ok())
110-
.or_else(|| crate::web_tools::current_base_url().ok())
111-
}
108+
// TODO(RR-1878): Would be great to grab this from the dataplatform when available.
112109

113-
#[cfg(not(target_arch = "wasm32"))]
110+
if let Some(url) = &self.viewer_base_url
111+
&& let Ok(url) = url.parse::<url::Url>()
114112
{
115-
// TODO(RR-1878): Would be great to grab this from the dataplatform when available.
113+
Some(url)
114+
} else if self.is_in_notebook || cfg!(not(target_arch = "wasm32")) {
115+
// Notebooks behave like native viewers here because just like on native,
116+
// there's no useful base url in the address bar to use.
116117
let version = re_build_info::build_info!().version.latest_stable();
117118

118119
url::Url::parse(&format!("https://rerun.io/viewer/version/{version}")).ok()
120+
} else {
121+
#[cfg(target_arch = "wasm32")]
122+
{
123+
crate::web_tools::current_base_url().ok()
124+
}
125+
126+
#[cfg(not(target_arch = "wasm32"))]
127+
{
128+
None
129+
}
119130
}
120131
}
121132
}
@@ -155,8 +166,7 @@ impl Default for StartupOptions {
155166
#[cfg(target_arch = "wasm32")]
156167
enable_history: false,
157168

158-
#[cfg(target_arch = "wasm32")]
159-
viewer_url: None,
169+
viewer_base_url: None,
160170
}
161171
}
162172
}

crates/viewer/re_viewer/src/web.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -661,21 +661,24 @@ impl From<PanelState> for re_types::blueprint::components::PanelState {
661661
// Keep in sync with the `AppOptions` interface in `rerun_js/web-viewer/index.ts`.
662662
#[derive(Clone, Default, Deserialize)]
663663
pub struct AppOptions {
664-
viewer_url: Option<String>,
665-
url: Option<StringOrStringArray>,
666664
manifest_url: Option<String>,
667665
render_backend: Option<String>,
668666
video_decoder: Option<String>,
669667
hide_welcome_screen: Option<bool>,
670-
panel_state_overrides: Option<PanelStateOverrides>,
671-
on_viewer_event: Option<Callback>,
672-
fullscreen: Option<FullscreenOptions>,
668+
// allow_fullscreen: Option<bool>, // Not serialized from js as it governs how the `fullscreen` option is used.
673669
enable_history: Option<bool>,
670+
// width: Option<String>, // Width & height aren't serialized and only used to configure the canvas.
671+
// height: Option<String>,
672+
fallback_token: Option<String>,
674673

674+
// Hidden `WebViewerOptions`
675+
// ------------
676+
viewer_base_url: Option<String>,
675677
notebook: Option<bool>,
676-
persist: Option<bool>,
677-
678-
fallback_token: Option<String>,
678+
url: Option<StringOrStringArray>,
679+
panel_state_overrides: Option<PanelStateOverrides>,
680+
on_viewer_event: Option<Callback>,
681+
fullscreen: Option<FullscreenOptions>,
679682
}
680683

681684
// Keep in sync with the `FullscreenOptions` interface in `rerun_js/web-viewer/index.ts`
@@ -720,7 +723,7 @@ fn create_app(
720723
};
721724

722725
let AppOptions {
723-
viewer_url,
726+
viewer_base_url,
724727
url,
725728
manifest_url,
726729
render_backend,
@@ -732,7 +735,6 @@ fn create_app(
732735
enable_history,
733736

734737
notebook,
735-
persist,
736738

737739
fallback_token,
738740
} = app_options;
@@ -762,7 +764,7 @@ fn create_app(
762764
max_bytes: Some(2_500_000_000),
763765
},
764766
location: Some(cc.integration_info.web_info.location.clone()),
765-
persist_state: persist.unwrap_or(true),
767+
persist_state: true,
766768
is_in_notebook: notebook.unwrap_or(false),
767769
expect_data_soon: None,
768770
force_wgpu_backend: render_backend.clone(),
@@ -784,7 +786,7 @@ fn create_app(
784786
panel_state_overrides: panel_state_overrides.unwrap_or_default().into(),
785787

786788
enable_history,
787-
viewer_url,
789+
viewer_base_url,
788790
};
789791
crate::customize_eframe_and_setup_renderer(cc)?;
790792

rerun_js/web-viewer/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,26 @@ export interface WebViewerOptions {
107107
// otherwise we need to restructure how we pass options to the viewer
108108

109109
/**
110-
* The public interface is @see {WebViewerOptions}
110+
* The public interface is @see {WebViewerOptions}. This adds a few additional, internal options.
111111
*
112112
* @private
113113
*/
114114
export interface AppOptions extends WebViewerOptions {
115-
/** The url that's used when sharing web viewer urls */
116-
viewer_url?: string;
115+
/** The url that's used when sharing web viewer urls
116+
*
117+
* If not set, the viewer will use the url of the page it is embedded in.
118+
*/
119+
viewer_base_url?: string;
120+
121+
/** Whether the viewer is running in a notebook. */
122+
notebook?: boolean;
123+
117124
url?: string;
118-
manifest_url?: string;
119-
video_decoder?: VideoDecoder;
120-
render_backend?: Backend;
121-
hide_welcome_screen?: boolean;
122125
panel_state_overrides?: Partial<{
123126
[K in Panel]: PanelState;
124127
}>;
125128
on_viewer_event?: (event_json: string) => void;
126129
fullscreen?: FullscreenOptions;
127-
enable_history?: boolean;
128130
}
129131

130132
// Types are based on `crates/viewer/re_viewer/src/event.rs`.

rerun_notebook/src/js/widget.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
type Panel,
44
type PanelState,
55
WebViewer,
6-
type WebViewerOptions,
6+
type AppOptions,
77
} from "@rerun-io/web-viewer";
88

99
import type { AnyModel, Render } from "@anywidget/types";
@@ -53,7 +53,8 @@ class ViewerWidget {
5353
viewer: WebViewer = new WebViewer();
5454
url: Opt<string> = null;
5555
panel_states: Opt<PanelStates> = null;
56-
options: WebViewerOptions = {
56+
options: AppOptions = {
57+
notebook: true,
5758
hide_welcome_screen: true,
5859
width: "100%",
5960
height: "100%",

0 commit comments

Comments
 (0)