Skip to content

allow customizing the restore condition - #20

Merged
manuelpuyol merged 1 commit into
mainfrom
mp/custom-restore
Mar 14, 2025
Merged

allow customizing the restore condition#20
manuelpuyol merged 1 commit into
mainfrom
mp/custom-restore

Conversation

@manuelpuyol

@manuelpuyol manuelpuyol commented Mar 14, 2025

Copy link
Copy Markdown
Collaborator

This enabled the consumer to setup a custom shouldRestore function to decide whether turbo should manage the b/f navigation

@manuelpuyol manuelpuyol changed the title allow customizing the restore condition and send the visit action to … allow customizing the restore condition and send the visit action to before-render event Mar 14, 2025
@manuelpuyol
manuelpuyol marked this pull request as ready for review March 14, 2025 21:22
Copilot AI review requested due to automatic review settings March 14, 2025 21:22
@manuelpuyol
manuelpuyol requested a review from a team as a code owner March 14, 2025 21:22
@manuelpuyol
manuelpuyol requested a review from gracepark March 14, 2025 21:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the framework to allow consumers to customize the restore condition and to transmit an action value when rendering snapshots.

  • Updates History to include a customizable shouldRestore function and modifies the popstate check to utilize it.
  • Updates TurboBeforeRenderEvent type and adjusts render methods signatures and calls across View and PageView to pass an optional action parameter.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/core/drive/history.ts Adds a customizable shouldRestore function and updates popstate handling.
src/core/session.ts Updates TurboBeforeRenderEvent to include an optional action property.
src/core/view.ts Modifies render method signature to accept and propagate an optional action.
src/core/drive/page_view.ts Updates render and renderError to pass the action parameter from visit.
Comments suppressed due to low confidence (2)

src/core/drive/history.ts:25

  • The new customizable 'shouldRestore' function is introduced without direct test coverage; add tests to verify its behavior.
shouldRestore: (state: any) => boolean = () => true

src/core/view.ts:94

  • The new 'action' property passed in the render options should be covered by tests to ensure correct propagation.
const options = { resume: this.resolveInterceptionPromise, render: this.renderer.renderElement, action }

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

@manuelpuyol

Copy link
Copy Markdown
Collaborator Author

idk why tests are not running, but I'm also not really worried about that with this PR...

@manuelpuyol manuelpuyol changed the title allow customizing the restore condition and send the visit action to before-render event allow customizing the restore condition Mar 14, 2025
@manuelpuyol
manuelpuyol merged commit 9ce5af9 into main Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants