-
Notifications
You must be signed in to change notification settings - Fork 429
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
Fire 'turbo:frame-render' event after turbo frame renders the view #327
Fire 'turbo:frame-render' event after turbo frame renders the view #327
Conversation
Any reason why |
Not really, just 2 concerns:
If you think that we should send the object itself, please let me know and I'll change it! |
I'm curious then how this is working in the code: const frame = this.element.id;
dispatch("turbo:after-frame-render", { cancelable: true, detail: { fetchResponse, frame } }) If If the id were to be the only thing passed, then perhaps naming it |
I guess that the testing suite represents the elements in a different way, causing the
Agree with the naming, if we pass only the id, |
I think the right event name should probably be |
Also, we should probably stick with the style where we declare this in Session following the form of |
We should pull in turbo:frame-load as well: #59 |
#59 is using this.element to put in the event, rather than the ID. I think that's a better form to follow here as well. |
Great! So, I'll try to implement notifyApplicationAfterFrameRender inside session and pass the element itself rather than the id, asap. I will also pull in turbo:frame-load as well. |
…'turbo:frame-render' event
I've pushed this commit which introduces the There, I've passed the frame element as the target of the event and removed it from the |
Looks good 👍 |
Closes hotwired#54 Closes hotwired/turbo-rails#56 Dispatch `turbo:frame-load` lifecycle event when `<turbo-frame>` element is navigated and finishes loading. The events bubble up, with the `<turbo-frame>` element as the target. Originally, this pull request involved numerous events, but in the spirit of experimentation, we'll start with the one and see if others are necessary.
I also cherry-picked #59's commit and resolved some conflicts |
@kapantzak (thanks for the contribution!) context: const html = await fetchResponse.responseHTML
if (html) {
const { body } = parseHTMLDocument(html)
const snapshot = new Snapshot(await this.extractForeignFrameElement(body))
const renderer = new FrameRenderer(this.view.snapshot, snapshot, false, false)
if (this.view.renderPromise) await this.view.renderPromise
await this.view.render(renderer)
session.frameRendered(fetchResponse, this.element)
session.frameLoaded(this.element)
this.fetchResponseLoaded(fetchResponse)
} Assuming 🤔 the main intention to provide document.addEventListener("turbo:frame-render", () => {
event.detail.fetchResponse.responseHTML.then((html) => {
const body = (new DOMParser()).parseFromString(html, "text/html")
})
}) In order to avoid reparsing what was just parsed, the detail of the Event could have the already parsed |
Hello @zeto , I think it makes sense! But maybe we should just add it as an extra prop instead of replacing the old one in order to avoid breaking existing imementations |
Hello all!
This PR introduces the
turbo:frame-render
event whichgets fired right after a turbo-frame element renders its view.
You can access the current turbo-frame
id withwithevent.detail.frameId
event.target
and the fetch response object withevent.detail.fetchResponse
.