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

✨ Allow Geo information in url rewriting #35558

Merged
merged 12 commits into from
Aug 10, 2021

Conversation

kristoferbaxter
Copy link
Contributor

@kristoferbaxter kristoferbaxter commented Aug 6, 2021

Addresses #35482. This isn't fully ready for merging (no tests!), but wanted feedback on the approach.

Now ready for review, including a test for the sync behaviour from a cached value.

This PR will likely need additional documentation to demonstrate the inherent race condition with requesting geo information to be available for a sync action.

src/service/url-replacements-impl.js Outdated Show resolved Hide resolved
}, 'AMP_GEO');
}
)
(geoType) => geoData(this.cachedGeo_, geoType),
Copy link
Member

Choose a reason for hiding this comment

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

I'm not too familiar with url-replacements, but isn't this a race condition? Is it fine to default to unknown before amp-geo service finishes loading?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's a race condition, but intentionally.

We opt to not interfering with delays when a user clicks on a link targetted by replacement by waiting for async data. If the data is not present for sync access here, a default fallback value is used.

Likely, if we do this, it will need some additional documentation.

Copy link
Member

Choose a reason for hiding this comment

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

Apologies if this is a silly question, but why does it need to be sync? Why can't the URL resolve async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the value is async, then users have to wait during a click event to start a navigation to the next document.

(I think we could also rewrite async items greedily as an alternative, but this isn't supported right now)

@kristoferbaxter kristoferbaxter marked this pull request as ready for review August 9, 2021 21:26
Copy link
Member

@samouri samouri left a comment

Choose a reason for hiding this comment

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

Thank you for writing tests!

We should also update documentation in https://github.com/ampproject/amphtml/blob/main/extensions/amp-link-rewriter/amp-link-rewriter.md#output-required.

Approving to unblock / since I'm not sure if you want to address that separately

@kristoferbaxter
Copy link
Contributor Author

SGTM, I'll make the documentation change following this PR landing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants