Skip to content

Commit

Permalink
fix(capsules): fixed capsules with exporting
Browse files Browse the repository at this point in the history
These were causing substantial errors because we were incorrectly
handling widget states.
  • Loading branch information
arctic-hen7 committed Jan 18, 2023
1 parent 9aaa6ac commit b6e0916
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/perseus/src/reactor/render_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub(crate) enum RenderMode<G: Html> {
/// An accumulator of the widget states involved in rendering this
/// template. We need to be able to collect these to later send
/// them to clients for hydration.
///
/// Importantly, widget states are *not* fallible at build-time!
/// Any errors will be propagated to terminate the build.
widget_states: Rc<RefCell<HashMap<String, (String, Value)>>>,
/// A list of widget paths that are either nonexistent, or able to be
/// incrementally generated. The build process should parse these and
Expand Down
15 changes: 13 additions & 2 deletions packages/perseus/src/turbine/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ impl<M: MutableStore, T: TranslationsManager> Turbine<M, T> {
.into())
}
};

// If it's a capsule, abort now
if template.is_capsule {
return Ok(());
}

// Create a locale detection file for it if we're using i18n
// These just send the app shell, which will perform a redirect as necessary
// Notably, these also include fallback redirectors if either Wasm or JS is
Expand Down Expand Up @@ -279,11 +285,16 @@ impl<M: MutableStore, T: TranslationsManager> Turbine<M, T> {
.immutable_store
.read(&format!("static/{}.widgets.json", full_path_encoded))
.await?;
// These are *not* fallible!
let widget_states = match serde_json::from_str::<
HashMap<PathMaybeWithLocale, Result<Value, ServerErrorData>>,
HashMap<PathMaybeWithLocale, (String, Value)>,
>(&widget_states)
{
Ok(widget_states) => widget_states,
// Same processing as the server does
Ok(widget_states) => widget_states
.into_iter()
.map(|(k, (_, v))| (k, Ok(v)))
.collect::<_>(),
Err(err) => return Err(ServerError::InvalidPageState { source: err }),
};
let head = self
Expand Down
1 change: 1 addition & 0 deletions packages/perseus/src/turbine/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl<M: MutableStore, T: TranslationsManager> Turbine<M, T> {
.read(&format!("static/{}.widgets.json", &path_encoded))
.await?
};
// From the build process, these are infallible
let widget_states = match serde_json::from_str::<
HashMap<PathMaybeWithLocale, (String, Value)>,
>(&widget_states)
Expand Down

0 comments on commit b6e0916

Please sign in to comment.