Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back support for SSR error boundaries #96

Closed
chrisetheridge opened this issue Feb 12, 2023 · 2 comments
Closed

Add back support for SSR error boundaries #96

chrisetheridge opened this issue Feb 12, 2023 · 2 comments
Labels
enhancement New feature or request ssr

Comments

@chrisetheridge
Copy link

chrisetheridge commented Feb 12, 2023

Is your feature request related to a problem? Please describe.
Currently you cannot properly implement SSR error boundaries, because the results of the error boundary render function are not processed by the SSR HTML renderer.

Describe the solution you'd like
I would like to be able to write an error boundary that can be used in both the JVM and JS. I can just do plain old try + catch, but that means we can't easily share component logic between platforms.

Describe alternatives you've considered
I've tried using try + catch on the JVM and that works. But this means you need 2 different component implementations when you want to use error boundaries, or at least 2 different component wrapper implementations.

I've also tried using error boundaries as they are now, but the returned UIx element is not compiled by the HTML renderer.

(defn create-error-boundary [{:keys [render-fn derive-error-state did-catch
                                     display-name]}]
  (fn [& args]
    (try
      (render-fn (atom nil) args)
      (catch Exception e
        (did-catch e display-name)
        (render-fn (atom (derive-error-state e)) args)))))

(def error-boundary
  (create-error-boundary
   {:derive-error-state (fn [error]
                          {:error error})
    :did-catch          (fn [error info]
                          (logging/error "Component did catch" error)
                          info)}
   (fn [state children]
     (logging/info "Render" @state children)
     (if (:error @state)
       (:error @state)
       children))))

Additional context
I think we can just use the UIx V1 error boundary approach as is, it works pretty well!

@roman01la roman01la added enhancement New feature or request ssr labels Feb 13, 2023
@roman01la
Copy link
Collaborator

resolved in #98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ssr
Development

No branches or pull requests

2 participants