-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace
rerenderInAction
to: renderPage
and `renderComponen…
…t` (#682) * docs: add new renderPage and renderComponent docs * feat: add renderPage and renderComponent * feat: adapt resolveAction to the new methods * fix: fix resolve rpc * test: fix test * feat: add warn to rerenderInAction * fix: fix types * feat: render element * feat: add target * feat: add target * feat: use target * feat: support append, prepend, before and after * fix: tests * reformat * chore: clean * fix: replace rerenderInAction * refactor
- Loading branch information
Showing
39 changed files
with
1,599 additions
and
561 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,6 @@ tsconfig.tsbuildinfo | |
## Panda | ||
styled-system | ||
styled-system-studio | ||
|
||
## Deno (we are using bun.lockb) | ||
deno.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
description: rerender the component inside a server action | ||
--- | ||
|
||
# renderComponent | ||
|
||
## Reference | ||
|
||
### `renderComponent({ element, target, mode, withTransition }: RenderComponentProps): Never` | ||
|
||
The `renderComponent` method is used to rerender the component or render some component in an specific target location inside a server action. Outside of an action, it throws an error. | ||
|
||
`renderComponent` needs to be called outside of the `try/catch` block: | ||
|
||
```tsx | ||
export default function MyComponent({ text = "foo" }: { text: string }) { | ||
function handleClick() { | ||
// Just a component rerender: | ||
renderComponent(); | ||
|
||
// Trigger a component rerender with new props | ||
renderComponent({ element: <MyComponent text="bar" />}); | ||
|
||
// Render a specific component on target location | ||
renderComponent({ | ||
element: <Component {...props} />, | ||
target: "#target-id", | ||
mode: "replace", | ||
withTransition: true, | ||
}); | ||
} | ||
|
||
return ( | ||
<div> | ||
<button onClick={handleClick}>{text}</button> | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
> [!NOTE] | ||
> | ||
> See the differences between "Action Signals" and `renderComponent` in [this documentation](/building-your-application/data-management/server-actions#action-signals-vs-rerender). | ||
#### Types: | ||
|
||
```ts | ||
function renderComponent<PropsType>( | ||
props: RenderComponentProps<PropsType> = {}, | ||
): never; | ||
|
||
type RenderComponentProps = { | ||
element?: JSX.Element; | ||
target?: string; | ||
placement?: 'replace' | 'before' | 'after' | 'append' | 'prepend'; | ||
withTransition?: boolean; | ||
}; | ||
``` | ||
|
||
#### Parameters: | ||
|
||
- `element` (optional): The component to render. By default, it will rerender the target component that triggered the action. | ||
- `target` (optional): The target location to render the component. It can be a CSS selector. | ||
- `placement` (optional): The placement to render the component. It can be `replace`, `before`, `after`, `append` or `prepend`. Default is `replace`. | ||
- `withTransition` (optional): If `true`, it will render the component with [start view transition API](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition). Default is `false`. | ||
|
||
#### Returns: | ||
|
||
- `Never` does not require you to use `return renderComponent()` due to using the TypeScript [`never`](https://www.typescriptlang.org/docs/handbook/2/functions.html#never) type. | ||
|
||
> [!CAUTION] | ||
> | ||
> Avoid using the `renderComponent` inside a `try/catch` block. The `navigate` is a throwable function and will break the execution of the current function. | ||
> [!TIP] | ||
> | ||
> Updating [`Action Signals`](/building-your-application/data-management/server-actions#action-signals) by default is going to use a `renderComponent` without you having to specify it. If you specify it, it will fulfill only the `renderComponent` you specify. | ||
### Support | ||
|
||
| Component | Support | | ||
| ----------------- | ------- | | ||
| Server Component | ❌ | | ||
| Web Component | ❌ | | ||
| SSR Web Component | ❌ | | ||
| Actions | ✅ | | ||
| Middleware | ❌ | | ||
| Response headers | ❌ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
description: rerender the page inside a server action | ||
--- | ||
|
||
# renderPage | ||
|
||
## Reference | ||
|
||
### `renderPage(): Never` | ||
|
||
The `renderPage` method is used to rerender the page inside a server action. Outside of an action, it throws an error. | ||
|
||
`renderPage` needs to be called outside of the `try/catch` block: | ||
|
||
```tsx | ||
import { renderPage } from "brisa/server"; | ||
|
||
// Inside a server action | ||
function handleEvent() { | ||
try { | ||
// ... | ||
} catch (error) { | ||
// ... | ||
} | ||
|
||
// Trigger a full-page rerender | ||
renderPage(); | ||
} | ||
``` | ||
|
||
> [!NOTE] | ||
> | ||
> See the differences between "Action Signals" and `renderPage` in [this documentation](/building-your-application/data-management/server-actions#action-signals-vs-rerender). | ||
### Parameters | ||
|
||
- `withTransition` (optional): A boolean value that indicates whether the rerender should be done with [start view transition](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition). Default is `false`. | ||
|
||
|
||
#### Types: | ||
|
||
```ts | ||
function renderPage(): never; | ||
``` | ||
|
||
#### Returns: | ||
|
||
- `Never` does not require you to use `return rerenderInPage()` due to using the TypeScript [`never`](https://www.typescriptlang.org/docs/handbook/2/functions.html#never) type. | ||
|
||
> [!CAUTION] | ||
> | ||
> Avoid using the `renderPage` inside a `try/catch` block. The `navigate` is a throwable function and will break the execution of the current function. | ||
### Support | ||
|
||
| Component | Support | | ||
| ----------------- | ------- | | ||
| Server Component | ❌ | | ||
| Web Component | ❌ | | ||
| SSR Web Component | ❌ | | ||
| Actions | ✅ | | ||
| Middleware | ❌ | | ||
| Response headers | ❌ | |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.