-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow islands to be re-rendered with new props on page transition (#1…
…0136) * Allow islands to be re-rendered with new props on page transition * Adjust the expected styles * Restore test expectation * Add changeset and final change * linting * Implement transition:persist-props behavior * Fix lockfile * Fix expectations * App is hyrid * Update .changeset/lovely-nails-cough.md Co-authored-by: Sarah Rainsberger <[email protected]> * Update .changeset/lovely-nails-cough.md Co-authored-by: Sarah Rainsberger <[email protected]> * Update .changeset/lovely-nails-cough.md Co-authored-by: Sarah Rainsberger <[email protected]> --------- Co-authored-by: Sarah Rainsberger <[email protected]>
- Loading branch information
1 parent
3307cb3
commit 9cd84bd
Showing
10 changed files
with
106 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
"@astrojs/react": minor | ||
"astro": minor | ||
--- | ||
|
||
Changes the default behavior of `transition:persist` to update the props of persisted islands upon navigation. Also adds a new view transitions option `transition:persist-props` (default: `false`) to prevent props from updating as needed. | ||
|
||
Islands which have the `transition:persist` property to keep their state when using the `<ViewTransitions />` router will now have their props updated upon navigation. This is useful in cases where the component relies on page-specific props, such as the current page title, which should update upon navigation. | ||
|
||
For example, the component below is set to persist across navigation. This component receives a `products` props and might have some internal state, such as which filters are applied: | ||
|
||
```astro | ||
<ProductListing transition:persist products={products} /> | ||
``` | ||
|
||
Upon navigation, this component persists, but the desired `products` might change, for example if you are visiting a category of products, or you are performing a search. | ||
|
||
Previously the props would not change on navigation, and your island would have to handle updating them externally, such as with API calls. | ||
|
||
With this change the props are now updated, while still preserving state. | ||
|
||
You can override this new default behavior on a per-component basis using `transition:persist-props=true` to persist both props and state during navigation: | ||
|
||
```astro | ||
<ProductListing transition:persist-props=true products={products} /> | ||
``` |
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
6 changes: 5 additions & 1 deletion
6
packages/astro/e2e/fixtures/view-transitions/src/pages/island-one.astro
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
--- | ||
import Layout from '../components/Layout.astro'; | ||
import Island from '../components/Island.jsx'; | ||
export const prerender = false; | ||
const persistProps = Astro.url.searchParams.has('persist'); | ||
--- | ||
<Layout> | ||
<p id="island-one">Page 1</p> | ||
<a id="click-two" href="/island-two">go to 2</a> | ||
<Island count={5} client:load transition:persist transition:name="counter" /> | ||
<Island count={5} page="Island 1" client:load transition:persist transition:name="counter" | ||
transition:persist-props={persistProps} /> | ||
</Layout> |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.