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

Use throw render() / throw redirect() inside React/Vue/Solid components #1707

Open
brillout opened this issue Jun 20, 2024 · 3 comments
Open
Labels
enhancement ✨ New feature or request

Comments

@brillout
Copy link
Member

Description

In principle, it should be possible to use throw render() and throw redirect() inside UI components.

For this to work, vike-{react,vue,solid} need to catch the exception and then re-throw it inside the onRenderHtml()/onRenderClient() hook, so that the exception propagates to Vike.

Contribution welcome.

@brillout brillout changed the title Use throw render() / throw redirect() inside React/Vue/Solid comopnents Use throw render() / throw redirect() inside React/Vue/Solid components Jun 20, 2024
@brillout
Copy link
Member Author

Deprioritizing, as per vikejs/vike-react#123 (comment).

@simplecommerce
Copy link

simplecommerce commented Oct 2, 2024

Is this not supposed to work already?
In my test project, I implemented vike-node and am using throw redirect() in a React Component I have, but only in SSR in order to redirect to another page when the user isn't logged-in, and it seems to work fine.

@brillout
Copy link
Member Author

brillout commented Oct 4, 2024

@simplecommerce Yes it already works if the onRenderHtml() and onRenderClient() hooks receive the exception thrown by throw redirect() / throw render(), and if you aren't using HTML streaming. Because it isn't clear what should happen when throw redirect() / throw render() is called during HTML Streaming (will browsers respect the redirect header after the HTML stream has started?), I recommend defining user redirections on a page level instead of a component level.

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

No branches or pull requests

2 participants