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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.22.8
20.10.0
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unreleased
- Add invalid id token handling for `current_shopify_domain` method [#1868](https://github.com/Shopify/shopify_app/pull/1868)
- Keep original path and params when redirecting deep links to embed [#1869](https://github.com/Shopify/shopify_app/pull/1869)
- Fix managed install path for SPIN environments [#1877](https://github.com/Shopify/shopify_app/pull/1877)
- Migrate fullpage redirect to App Bridge CDN [#1870](https://github.com/Shopify/shopify_app/pull/1870)

22.2.1 (May 6,2024)
----------
Expand Down
5 changes: 0 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,3 @@ To run tests, you'll need to make sure that your development environment is setu
* To run all tests: `bundle exec rake test`
* To run a specific test file: `bundle exec rake test TEST=test/controllers/callback_controller_test.rb`
* To run a single test: `bundle exec rake test TEST=test/controllers/callback_controller_test.rb:50` where `50` is the line number on or inside the test case.

### App Bridge client

This gem ships with a UMD version of the App Bridge client. It lives inside the assets folder: `app/assets/javascripts/shopify_app/`. To update the client, simply download the UMD build from [unpkg.com](https://unpkg.com/@shopify/app-bridge) and save it into the folder.
Please follow the convention of including the client version number in the filename. Finally, change the reference to the new App Bridge client inside `app/assets/javascripts/shopify_app/app_bridge_redirect.js`.
10 changes: 0 additions & 10 deletions app/assets/javascripts/shopify_app/app_bridge_3.7.8.js

This file was deleted.

22 changes: 0 additions & 22 deletions app/assets/javascripts/shopify_app/app_bridge_redirect.js

This file was deleted.

12 changes: 3 additions & 9 deletions app/assets/javascripts/shopify_app/redirect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//= require ./app_bridge_redirect.js

(function () {
function redirect() {
var redirectTargetElement = document.getElementById("redirection-target");
Expand All @@ -9,14 +7,10 @@
}

var targetInfo = JSON.parse(redirectTargetElement.dataset.target);
var normalizedLink = document.createElement('a');
normalizedLink.href = targetInfo.url;

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

if (appBridgeUtils.isShopifyEmbedded()) {
window.appBridgeRedirect(targetInfo.url);
} else {
window.top.location.href = targetInfo.url;
}
open(normalizedLink.href, '_top');
}

document.addEventListener("DOMContentLoaded", redirect);
Expand Down
6 changes: 5 additions & 1 deletion app/views/shopify_app/shared/redirect.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<base target="_top">
<title>Redirecting…</title>

<meta name="shopify-api-key" content="<%= ShopifyApp.configuration.api_key %>">
<%= javascript_include_tag "https://cdn.shopify.com/shopifycloud/app-bridge.js" %>

<%= javascript_include_tag('shopify_app/redirect', crossorigin: 'anonymous', integrity: true) %>
</head>
<body data-api-key="<%= ShopifyApp.configuration.api_key %>" data-shop-origin="<%= current_shopify_domain %>" data-host="<%= params[:host] %>" >
<body>
<%=
content_tag(:div, nil,
id: 'redirection-target',
Expand Down
66 changes: 0 additions & 66 deletions test/javascripts/shopify_app/app_bridge_redirect_test.js

This file was deleted.

20 changes: 12 additions & 8 deletions test/javascripts/shopify_app/redirect_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
suite('redirect', () => {
const redirectHelperSandbox = sinon.createSandbox();
const { assert } = require("chai");

suite('redirect', () => {
const sandbox = sinon.createSandbox();
const open = sinon.spy();
let contentContainer;
let url = '/settings';

Expand All @@ -10,17 +12,19 @@ suite('redirect', () => {
contentContainer.setAttribute('id', 'redirection-target');
contentContainer.dataset['target'] = JSON.stringify({url});
document.body.appendChild(contentContainer);

redirectHelperSandbox.stub(window, 'appBridgeRedirect').callsFake(() => {});
sandbox.stub(window, 'open').callsFake(open);
});

teardown(() => {
redirectHelperSandbox.restore();
sandbox.restore();
document.body.removeChild(contentContainer);
});

test('calls appBridgeRedirect', () => {
test('opens redirect url', () => {
require('../../../app/assets/javascripts/shopify_app/redirect');
sinon.assert.calledWith(window.appBridgeRedirect, url);

assert(open.calledOnce);
assert.match(open.lastCall.args[0], new RegExp(`${url}$`));
assert.equal(open.lastCall.args[1], '_top');
});
});
});
Loading