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

fix: client prerender fallback #10295

Merged
merged 4 commits into from
Mar 7, 2024
Merged

fix: client prerender fallback #10295

merged 4 commits into from
Mar 7, 2024

Conversation

rossrobino
Copy link
Contributor

Changes

Prerendering with the Speculation Rules API can fail---for example, certain Chrome extensions like LastPass can block prerendering, or browsers like Arc have disabled the feature. Currently in this case, neither prerendering or prefetching occurs.

Adding a link tag in addition to the speculation rules script does not create an extra request. This change will append the speculation rules script, in addition to prefetching with link or fetch to ensure at least prefetching will occur.

Testing

No modifications needed.

Docs

/cc @withastro/maintainers-docs for feedback!

Copy link

changeset-bot bot commented Mar 1, 2024

🦋 Changeset detected

Latest commit: 8b62a13

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Mar 1, 2024
@bluwy
Copy link
Member

bluwy commented Mar 4, 2024

If those extensions block prerendering, wouldn't they also block prefetching? And if Arc disables the feature, wouldn't HTMLScriptElement.supports('speculationrules') be false? I'm a bit worried about this approach, ideally we trust prerendering as the way for snappier navigations in the future, and wouldn't fallback to the old approach again.

@rossrobino
Copy link
Contributor Author

Thanks @bluwy, agreed that it doesn't seem like it should be necessary if the API is supported.

Discussing this issue on the Speculation Rules spec repo to ensure the best approach is implemented.

@bluwy
Copy link
Member

bluwy commented Mar 5, 2024

Thanks for the link (and hooking me on the email conversation). Yeah I think it's nicer if the API can fallback to prefetching if prerender is blocked.

I've also found adding the url to both prefetch and prerender works as well.

Seems like Domenic also recommended this. If it doesn't cause a double fetch, I like this approach too!

@rossrobino
Copy link
Contributor Author

Of course! Thanks for looking this over. Domenic suggested still using the Speculation Rules API to prefetch in this case instead of a link tag due to the benefits stated here. I have made those changes, so I think it's all set to fallback using the recommended approach now.

@ematipico ematipico merged commit fdd5bf2 into withastro:main Mar 7, 2024
14 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants