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

Migrate fullpage redirect to App Bridge CDN #1870

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

kirillplatonov
Copy link
Contributor

@kirillplatonov kirillplatonov commented Jun 24, 2024

What this PR does

Switching from hardcoded AppBridge 3 version to AppBridge CDN. This removes the need to pass params[:host] for fullpage_redirect_to helper and fixes redirect with token exchange auth. I manually tested it with both token exchange and legacy auth.

Checklist

Before submitting the PR, please consider if any of the following are needed:

  • Update CHANGELOG.md if the changes would impact users
  • Update README.md, if appropriate.
  • Update any relevant pages in /docs, if necessary
  • For security fixes, the Disclosure Policy must be followed.

@kirillplatonov kirillplatonov requested a review from a team as a code owner June 24, 2024 07:04
@kirillplatonov kirillplatonov force-pushed the migrate-fullpage-redirect branch 2 times, most recently from 71de717 to e78f74a Compare June 24, 2024 08:35
@@ -1 +1 @@
12.22.8
Copy link
Contributor Author

@kirillplatonov kirillplatonov Jun 24, 2024

Choose a reason for hiding this comment

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

Upgraded as v12 no longer maintained and I couldn't install it locally

@kirillplatonov
Copy link
Contributor Author

cc @zzooeeyy @paulomarg

@kirillplatonov
Copy link
Contributor Author

@matteodepalo please take a look at this one too. It's important upgrade to move forward with migration to id_token.

@matteodepalo
Copy link
Contributor

Hi @kirillplatonov, we're taking a look now.

Copy link

@byrichardpowell byrichardpowell left a comment

Choose a reason for hiding this comment

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

Minor feedback, but approving so you can ship if you don't think the comments or important, or once you've addressed them

var appBridgeUtils = window['app-bridge']['utilities'];

if (appBridgeUtils.isShopifyEmbedded()) {
if (window['shopify']) {

Choose a reason for hiding this comment

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

In what situation do we need the else here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it as open should cover both embedded and non-embedded context now (great design decision)

var normalizedLink = document.createElement('a');
normalizedLink.href = url;

Redirect.create(app).dispatch(Redirect.Action.REMOTE, normalizedLink.href);
open(normalizedLink.href, '_top');

Choose a reason for hiding this comment

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

🎉

sinon.stub(Redirect, 'create').callsFake(() => RedirectInstance);

const normalizedUrl = `${window.location.origin}${url}`;
test('calls App Bridge redirect to normalized url', () => {

Choose a reason for hiding this comment

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

Not sure this test name is quite true? It's calling window.open? Do we need two tests here? One to test that the App Bridge script tag is in the page and one to test we called window.open?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged and renamed tests. To be honest, I don't like that kind of tests where everything is stabbed and no real behavior being tested. But not sure if there's a better way to test App Bridge. It's a common issue for testing app related code that works with App Bridge too.

@@ -1,21 +1,9 @@
//= require ./app_bridge_3.7.8.js

(function(window) {
function appBridgeRedirect(url) {

Choose a reason for hiding this comment

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

From what I can see, this function is only used once. Instead of adding this function to the window object, could we just called open(normalizedLink.href, '_top') directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, simplified and removed unnecessary function 👍

@kirillplatonov
Copy link
Contributor Author

@byrichardpowell made adjustments based on your feedback. Code become even simpler 👍

@lizkenyon lizkenyon merged commit e2ba23d into Shopify:main Jul 10, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants