-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow islands to be re-rendered with new props on page transition #10136
Conversation
🦋 Changeset detectedLatest commit: 4a99bab The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
Wow @matthewp, that looks really cool! Preserved state and updated props! Three questions came to my mind:
|
@martrapp I think for non-islands it's a bit trickier to determine what to do. For example, on a This is true of islands to, of course. My assumption here is that islands are more adept to respond to the changes and keep the current state if that's the right thing to do. So I do think we should do a preview release here and have some people use it to see if it matches their expectations or not. We could provide an option in / out directive in either case. |
Bad example :), but i know what you mean
A nice example for non-islands would be updating the class attribute as transition:persist copies over the element with the current class attribute, but not the CSS referenced from the class attribute. Updating the class attribute with the values from the next page would guarantee that the referenced classes are found in the style sheets of the next page. Of course, this can all be done using lifecycle events and no need to include it in the core implementation. But there may be a point to give users some control over whether their island props being updated automatically ;-) |
@martrapp What about something like:
Not sold on this tbh, just getting the conversation moving. |
Hey @matthewp
Yes, great!
|
@martrapp Ok, I'll update the PR to implement |
Sounds good to me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @matthewp ! Following the conversation in this PR, I also wanted to add mention here of transition:persist-props
as I think that's important to call out!
Also, the PR title says "islands" which we've always taken to mean a UI framework component. (e.g. not an Astro component) but doesn't mean our audience is necessarily going to have that distinction top of mind.
This changeset description uses "island" and "component" interchangeably, and no where screams "YOU CAN'T USE THIS ON AN ASTRO COMPONENT". I didn't add anything to that effect, but it could be worth a stronger, explicit mention somewhere if that's the case. It can be as simple as updating a couple of the times where the word "component" is used to "framework component" for example. So, you can decide whether you think that's necessary.
So, see what you think of my suggestions for your consideration!
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving for docs, so it's clear!
I think it works differently now than described in the documentation. transition:persist-propsThe documentation says: This allows you to control whether or not an island’s props should be persisted upon navigation. By default, when you add transition:persist to an island, the state is retained upon navigation, but your component will re-render with new props. This is useful, for example, when a component receives page-specific props such as the current page’s title. You can override this behavior with transition:persist-props. Adding this directive will keep an island’s existing props (not re-render with new values) in addition to maintaining its existing state. Now it works exactly the other way around. When I have transition:persist, all props are preserved, but when I use transition:persist-props, they are reset when the page changes. |
Hi @Fakerko there might be a miss-understanding: For a navigation from "from" to "to", Do you have a counterexample that I should have a look at? |
Hi @martrapp, I made an example on Codesandbox. The first component uses transition:persist and the second uses transition:persist-props. Once you click on "Update values" in the components and go to the "About" page, for the component with transition:persist the component values are preserved, but for the component with transition:persist-props they are reset. |
Yes.
|
Oh, I get it. So it's working as it should, I'm sorry. My understanding was that transition:persist-props preserves the component values, and transition:persist preserves the component but without the values. Thanks a lot! |
Let's see if we can make that more clear in the docs. ;-) |
Maybe add an example at the end of transition:persist-props block, something like this: Component will be re-rendered with new props: Component will keep the existing props: |
At least we have to better point out, that Thank you very much for your feedback. Obviously this is complicated. |
Demo1.mp4
Changes
Testing
Docs