-
Notifications
You must be signed in to change notification settings - Fork 430
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
Move cache snapshot loading to Visit#start() #1056
Conversation
The cache interface changed in #949 Since the cache can be loaded from disk using the browser Cache API, it is possible that the cache snapshot will be loaded asynchronously. This means that the calls to load cache snapshots need to be awaited. We also changed visit.hasCachedSnapshot() to be async and return a Promise. However, [hasCachedSnapshot is used in the iOS adapter](https://github.com/hotwired/turbo-ios/blob/c476bac66f260adbfe930ed9a151e7637973ff99/Source/WebView/turbo.js#L119) and serialized into and data object we send to the native side via postMessage. When postMessagereceives a Promise instead of a boolean value it fails with a DataCloneError since it can't serialize the Promise. This commit moves the cache snapshot loading to Visit#start() and stores the result in a cachedSnapshot property. This allows us to keep the hasCachedSnapshot() method synchronous and return a boolean value. It means that Visit.start is now async, but I haven't found any callers that rely on it being synchronous.
* origin/main: Tests: remove `"test"` docstring prefix (#1052)
This happened before (#720). Should we test that the object sent to the native adapters conforms to the structured clone algorithm? |
…ch is what the native adapters expect
…ther tests were recently updated to remove the prefix
Good call @domchristie, I added a unit test to check that |
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.
Thank you, looks good to me @afcapel 👍
@domchristie agreed, this is a recurrent problem. It's too easy to make a mistake here 👍
How would that work? Do we add that to the iOS and Android adapters? |
@afcapel I had a quick look into adding some unit tests on this repo to make sure that anything sent to the native adapter methods doesn't raise an error when passed to @kevinmcconnell and I discussed some ideas in #720, and it was suggested that the ideal solution would be something on the native adapter side, but backwards compatibility was an issue. (Perhaps less so with a Turbo 8 major version change?) I implemented @kevinmcconnell's idea of adding a I am not a fan of types (and don't wish to bring up that debate again), but I think this might be a good place for them. In an earlier PR I added a So there's my thoughts! Not sure what the best approach is really! :/ |
* Revert "Move cache snapshot loading to Visit#start() (#1056)" This reverts commit e07639f. * Revert "Fix back navigation after POST form submission (#1014)" This reverts commit c207f5b. * Revert "Add disk cache store (#949)" This reverts commit f86a376. * Remove redudant test prefix * Bring back test Orginally added by @jayohms in 60cfbee
This fixes a problem introduced when the cache interface changed in #949
Since the cache can be loaded from disk using the browser Cache API, it is possible that the cache snapshot will be loaded asynchronously. This means that the calls to load cache snapshots need to be awaited.
Because of that we also changed
visit.hasCachedSnapshot()
to be async and return aPromise
. However, hasCachedSnapshot is used in the iOS adapter and serialized into and data object we send to the native side viapostMessage
. WhenpostMessage
receives a Promise instead of a boolean value it fails with aDataCloneError
because it can't serialize thePromise
.This commit moves the cache snapshot loading to
Visit#start()
and stores the result in acachedSnapshot
property. This allows us to keep thehasCachedSnapshot()
method synchronous and return a boolean value.It means that
Visit.start
is now async, but I haven't found any callers that rely on it being synchronous.