Replies: 16 comments 22 replies
-
|
Are the events meant to be blocking or not blocking? |
Beta Was this translation helpful? Give feedback.
-
|
The following diagram shows a simplified representation of the status quo. When The upper red arrow is when the view transition API takes the "screenshot" for the The view transition itself should not be delayed by loading the DOM or similar, as the view would appear frozen during this time. There should also be no new layout or rendering of the current page between these two arrows, as this would be seen as flickering. The green blocks are where the current events are dispatched. graph TD
subgraph rout[router.ts]
subgraph API
direction LR
nav("navigate()")
subgraph Events
eas("astro:after-swap")
eal("astro:load")
end
end
subgraph flow[Processing Flow]
osp{"same<br>page?"}
ff("Load newDocument from URL")
hco("Postprocess newDocument")
ssp("Save scroll position")
subgraph VTR["<b>View Transition</b>"]
psl("Preload style links")
subgraph Swap
swb("Merge <html>-attributes,<br><head> and <body><br>of current and newDOM")
mpe("Copy over persisted elements")
uhsp2("Move to Location")
emas("Dispatch astro:after-swap")
end
end
uhsp["Move to Location"]
flowend["end"]
RS("Run Scripts")
empl("Dispatch astro:page-load")
AN("Announce")
end
end
nav-->osp--"no"-->ff-->hco-->ssp-->psl-->swb-->mpe-->uhsp2-->emas-->RS-->empl-->AN-->flowend
osp--"yes"-->uhsp------>flowend
style emas fill:#060,stroke:#333,stroke-width:4px
style empl fill:#060,stroke:#333,stroke-width:4px
linkStyle 4,9 stroke:#f00
|
Beta Was this translation helpful? Give feedback.
-
|
The design principles for View Transitions are an easy-to-use solution with only a few lines of client-side code. While this works well in most cases, there are many innovative ideas on how to extend the current solution. While some of these are suitable for most users, others could be considered niche requirements that are beyond the scope and maintainability of the core implementation. I would like to add some scenarios from users about what they expect from view transitions. We could use those to evaluate the new API. Some of them might become part of the core implementation. But if the new API supports it, some requirements that we don't see in the core could also be realized as add-on and community solutions.
|
Beta Was this translation helpful? Give feedback.
-
|
For the API extension I would like to see something like the following: graph TD
subgraph rout[router.ts]
subgraph API
direction TB
nav("navigate()")
subgraph Events
epr("astro:transition-prepare")
ebs("astro:before-swap")
eas("astro:after-swap")
eal("astro:load")
end
end
subgraph flow[Processing Flow]
emtp("Fire astro:transition-prepare")
subgraph newDOM["Prepare Transition"]
ff("Load newDocument from URL")
hco("Postprocess newDocument")
end
ssp("Save scroll position")
psl("Preload style links")
subgraph VTR["<b>View Transition</b>"]
embs("Fire astro:before-swap")
subgraph Swap
direction TB
swb("Merge <html>-attributes,<br><head> and <body><br>of current and newDOM")
mpe("Move persisted elements")
uhsp2("Move to Location")
end
emas("Fire astro:after-swap")
end
flowend["end"]
RS("Run Scripts")
empl("Fire astro:page-load")
AN("Announce")
end
end
nav-->emtp-->ff-->hco-->ssp-->psl-->embs-->swb-->mpe-->uhsp2-->emas-->RS-->empl-->AN-->flowend
style emtp fill:#cc0,stroke:#333,stroke-width:4px,color:#000
style embs fill:#cc0,stroke:#333,stroke-width:4px,color:#000
style emas fill:#060,stroke:#333,stroke-width:4px,color:#fff
style empl fill:#060,stroke:#333,stroke-width:4px,color:#fff
linkStyle 5,10 stroke:#f00
|
Beta Was this translation helpful? Give feedback.
-
|
This is my proposal for the new events: Names, as always, are up for discussion and I welcome the support of the experts here. Of course, this also applies to all other aspects of the proposal! There are two new events, Both events inherit from a common There are also the typical members inherited from Event, with
|
Beta Was this translation helpful? Give feedback.
-
|
The intercept calls allow additional steps to be added to the processing flow. Basically you can get: graph TD
subgraph flow[Processing Flow]
emtp("Fire astro:transition-prepare")
subgraph newDOM["Prepare Transition"]
ff("Load newDocument from URL")
hco("Postprocess newDocument")
end
ssp("Save scroll position")
psl("Preload style links")
subgraph VTR["<b>View Transition</b>"]
embs("Fire astro:before-swap")
subgraph Swap
direction TB
swb("Merge <html>-attributes,<br><head> and <body><br>of current and newDOM")
mpe("Move persisted elements")
uhsp2("Move to Location")
end
emas("Fire astro:after-swap")
end
end
emtp-->ff-->hco-->pi1("prepare intercept 1")-->pi2("prepare intercept 2")-->pi3("...")-->ssp-->psl-->embs-->swb-->mpe-->uhsp2-->si1("swap intercept 1")-->si2("swap intercept 2")-->si3("...")-->emas
style emtp fill:#cc0,stroke:#333,stroke-width:4px,color:#000
style embs fill:#cc0,stroke:#333,stroke-width:4px,color:#000
style emas fill:#060,stroke:#333,stroke-width:4px,color:#fff
style newDOM fill:#606,stroke:#333,stroke-width:4px,color:#fff
style Swap fill:#606,stroke:#333,stroke-width:4px,color:#fff
linkStyle 7 stroke:#f00
The purple blocks are the default implementations for prepare and swap. Calling If you want to replace the default document loading with your own DOM manipulation/creation function, you would call If you want to replace the default swap function with your own, call The the interception steps are executed in order. The next step is only executed once the Promise of its predecessor fulfills. |
Beta Was this translation helpful? Give feedback.
-
|
Here is a TypeScript example what it would look like to add a flow step in the preparation phase that preloads the pictures in the new document before the view transition starts (see discord #support thread "First time view transitions between small and big images") The |
Beta Was this translation helpful? Give feedback.
-
|
Changed in the Event definition above:
To be discussed: Normally event properties are read-only to separate state from signaling. We could use setters/getters as in |
Beta Was this translation helpful? Give feedback.
-
|
With regard to further compatibility with the navigation API: Call
For the TransitionPrepareEvent, this would abort the navigation. For the TransitionBeforeSwapEvent this does not make sense. We could instead set Calling
The navigation API does many things better than the history API. So we should follow it where it makes sense. However, it has become complicated compared to its origins. It should not be our goal for Astro to mimic it down to the smallest detail. What I see out of scope are the history entries and the intercept options like "commit" or "scroll". CHANGE: That is a strong argument to go with Matthew's suggestion that calling You may wonder why we have two events with intercept options while the navigation API has only one: |
Beta Was this translation helpful? Give feedback.
-
|
In the last few days I have completed a large part of a proof of concept in which The benefit of integrating with the navigation API is that in the long run we can get rid of a lot of the code that is currently maintained by Astro but will become redundant by using the API
Thus, using the |
Beta Was this translation helpful? Give feedback.
-
|
This proposal now defines three new events:
The astro:after-* events are simple signals, the astro:before-* events enable the modification of parts of the astro view transition implementation (via The proposal for the
The event is triggered on Two additional events are proposed for preparing the transition: The proposal for the
The event is fired on The Added 11/10: The initial values of the properties for the |
Beta Was this translation helpful? Give feedback.
-
|
I just added |
Beta Was this translation helpful? Give feedback.
-
|
I just marked Plus: Clarification on how property values flow from |
Beta Was this translation helpful? Give feedback.
-
|
Hey everyone, I've been following the discussion about the new events you are going to add ( I was wondering if you think its a good idea to split the events between pages transition and forms submissions (maybe Framework agnostic:Using nanostores like Reactimport { useState, useEffect } from 'react';
function useForm(formId) {
const [formStatus, setFormStatus] = useState({
from: null,
to: null,
direction: '',
navigationType: '',
info: {},
newDocument: null,
formData: null,
error: null,
loading: false,
data: null
});
useEffect(() => {
function handleFormStart(event) {
if (event.detail.formId === formId) {
setFormStatus(prevStatus => ({
...prevStatus,
from: event.detail.from,
to: event.detail.to,
direction: event.detail.direction,
navigationType: event.detail.navigationType,
info: event.detail.info || {},
formData: event.detail.formData,
loading: true,
error: null
}));
}
}
function handleFormError(event) {
if (event.detail.formId === formId) {
setFormStatus(prevStatus => ({
...prevStatus,
error: event.detail.error,
loading: false
}));
}
}
function handleFormEnd(event) {
if (event.detail.formId === formId) {
setFormStatus(prevStatus => ({
...prevStatus,
loading: false,
data: event.detail.data
}));
}
}
window.addEventListener('astro:form-start', handleFormStart);
window.addEventListener('astro:form-error', handleFormError);
window.addEventListener('astro:form-end', handleFormEnd);
return () => {
window.removeEventListener('astro:form-start', handleFormStart);
window.removeEventListener('astro:form-error', handleFormError);
window.removeEventListener('astro:form-end', handleFormEnd);
};
}, [formId]);
return { formStatus };
}
export default useForm;PS: In the context of ViewTransitions form handling, how could Astro handle endpoint responses in non-HTML formats, such as JSON or other media types? I know you can opt out of router transition with PS2: Maybe I'm confused and mixing things, sorry for that :) Thank you! |
Beta Was this translation helpful? Give feedback.
-
|
Added |
Beta Was this translation helpful? Give feedback.
-
|
@martrapp can we close this proposal? I think we have all those events now |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
Add more events in the view transition router to give users greater control.
Background & Motivation
The ViewTransitions router currently omits 2 events, but we have gotten requests for more in the past. This proposal is to discuss new potential events.
Goals
Events
astro:before-swapBeta Was this translation helpful? Give feedback.
All reactions