Skip to content
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

Adapt to new history blocking API #1644

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

fheft
Copy link
Contributor

@fheft fheft commented Jun 10, 2023

Summary

  • The <Prompt> component is currently broken, throwing an exception whenever it should prompt, breaking the page.
  • The 'history' project changed the API used to block transitions, starting with v5.x.
  • Instead of accepting a message string, it now requires a callback function that handles the browser prompt itself.

Objective

This PR fixes an exception when using the <Prompt> router component. The regression was probably introduced with a95f57e, when the history dependency was updated to v5.x.
This version change came with a breaking change of the history.block() API that is used to block transitions between pages (i.e. the sole purpose of the <Prompt> component).

The v5 API requires the parameter of history.block(...) to be a function, whereas older versions also accepted a string.
See the documentation of the history project: Blocking Transitions (v4) vs Blocking Transitions (v5)

This PR uses the suggested code from the history project to restore the functionality as it was before.

How to test

I am not sure how this can be tested automatically. If anyone can give me a hint I'm happy to add a test.

It can easily be verified manually though:

  1. Add the <Prompt> component to the 'About' page of the inferno-router-demo (like that)
  2. Start the example project, navigate to the 'About' page, try to navigate back
  3. Nothing happens, exception in the browser console
  4. Using the fix from this PR, it will work as expected.

* The 'history' project changed the API used to
  block transitions, starting with v5.x.
* Instead of accepting a message string, it now
  requires a callback function that handles the
  browser prompt itself.
@Havunen
Copy link
Member

Havunen commented Jun 13, 2023

Hi, thanks for the PR. The change looks good to me.

@SleeplessOne1917
Copy link

@Havunen will this be merged and in a release soon? Something I'm working on uses this package as a dependency and I had to handroll my own prompt component because the current one does not work.

@Havunen Havunen merged commit 68213f0 into infernojs:master Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants