Skip to content

Document triggering navigation#4756

Merged
sarah11918 merged 19 commits into
mainfrom
astro-docs-navigate
Sep 28, 2023
Merged

Document triggering navigation#4756
sarah11918 merged 19 commits into
mainfrom
astro-docs-navigate

Conversation

@matthewp

@matthewp matthewp commented Sep 19, 2023

Copy link
Copy Markdown
Contributor

What kind of changes does this PR include?

  • New or updated content

Description

  • Created a section "Router control" to explain how you can have control over the router.
  • Added a section on manually triggering navigation.

Related Issue / Implementation PR

For Astro version: 3.2. See Astro PR #.

@netlify

netlify Bot commented Sep 19, 2023

Copy link
Copy Markdown

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit e7cd7e5
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/6515c5bc6ddbd1000868b85a
😎 Deploy Preview https://deploy-preview-4756--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sarah11918 sarah11918 added the merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) label Sep 19, 2023

@martrapp martrapp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Excluding PDFs and images from transitions is no longer a good example, since now all non-html files are reloaded anyway as well as all html-files that do not have <ViewTransitions /> in their head.

The way it is worded now, it might give the impression that people have to opt out.

We should also clearly state that both pages of the navigation must have <ViewTransitions /> in their <head> to prevent reload. (actually any element with a name=astro-view-transitions-enabled somewhere in the document)

The use case for astro-data-reload would be a navigation to another html page, to which you would normally want transitions (why else would the target page have <ViewTransitions />?), but on this very link between those two pages there should be a full reload. Now I'm starting to run out of imagination. Are there still any other good examples of data-astro-reload?

In the above cases data-astro-reload might be a performance optimizer: The checks for media-type and astro-view-transitions-enabled can only be performed after the target document has been retrieved. If a reload is forced, it must be loaded again. In contrast, data-astro-reload is checked first when a link is clicked, and there is no double loading, which can be important if it takes a long time to generate and load the image that can not be cached.

@matthewp

Copy link
Copy Markdown
Contributor Author

@martrapp Ah yes, that example was added before the media type check was added, so it was the right way to do it at the time. I would probably still use the tag to prevent an unnecessary fetch + redirect, but I agree that there can be a better example. I'll update this.

@martrapp martrapp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love your examples!

@sarah11918 sarah11918 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK! I apologize that a Github review is a terrible way to do this. I've made some structural change suggestions, and pointed out a couple of things that will need some clarification and checking.

I really wished this were nicer, but that one stupid deleted line over which I can't edit meant I had to leave several comments around it.

See what you think about incorporating some of my suggestions! And of course, make them accurate. 😅 @matthewp @martrapp

Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment on lines +273 to +275
The `navigate` method takes these arguments:

- `href` - The path to the page you wish to navigate. The href must be to within the same origin. Any external links will trigger redirection.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
The `navigate` method takes these arguments:
- `href` - The path to the page you wish to navigate. The href must be to within the same origin. Any external links will trigger redirection.
The `navigate` method takes one argument:
- `href` - The new page to navigate to. This must be a relative URL to a page within your own domain. Any external links will trigger redirection.

I can see that more options are planned, but if there's only one, we should really say one. 😄

And, the example above doesn't make it clear what the format should be because the content of the link is actually in a selected value. If someone were writing a path directly, would it be a relative URL like a normal link? (e.g. /about/) I think more explanation is necessary for this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The href does not have to be relative. It can be absolute, it can even be complete with protocol, host & post.
And while it may be too complicated to explain here, I suppose it can even have a different origin without triggering a reload if the target page has the correct CORS headers.

Suggestion:
The navigate method takes one argument:

  • href - The new page to navigate to.

If an error occurs while loading the target page, the navigate function falls silently back to a normal browser load with no view transitions. Typical errors are:

  • The document cannot be loaded due to an invalid href
  • The document is not an HTML document
  • The target page does not define <ViewTransitions/>
  • The target page and the current page do not have the same origin (protocol, host, port) and there are no other measures to support CORS (Cross-Origin Resource Sharing).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are going to have other options, so I'll go ahead and add them here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These have been added now, and the wording on href updated.

matthewp and others added 6 commits September 25, 2023 10:04
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

@yanthomasdev yanthomasdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adding a few nits here!

Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>

@sarah11918 sarah11918 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mini review, still working on the second part of the document, which seeing it now makes me want to make some structural changes... so publishing these to get them out of the way!

Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
@sarah11918

sarah11918 commented Sep 27, 2023

Copy link
Copy Markdown
Member

Left lots of little comments above as I made changes, and this new section can be revisited once we have these options all on a reference page, too. For now, I think what we have balances needing to surface the new options released while providing use-case based sections and examples.

Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Co-authored-by: Martin Trapp <94928215+martrapp@users.noreply.github.com>
@martrapp martrapp self-requested a review September 27, 2023 11:32

@martrapp martrapp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks Good! Tank you!

Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
Comment thread src/content/docs/en/guides/view-transitions.mdx Outdated
@sarah11918 sarah11918 merged commit 84a5711 into main Sep 28, 2023
@sarah11918 sarah11918 deleted the astro-docs-navigate branch September 28, 2023 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants