Is there any actual documentation for how @shopify/app-bridge-react is supposed to be used? It seems like it’s been half baked and released without a lot of supporting information.
Currently, I’m trying to get a Modal component to render, but any time I add the component and reload the app, I get loads of error messages like:
AppBridgeError {name: "AppBridgeError", message: "APP::ERROR::INVALID_OPTIONS: `type_error_expected_string thrown for path: ['message'] and value: `undefined`", action: undefined, type: "APP::ERROR::INVALID_OPTIONS", stack: "AppBridgeError: APP::ERROR::INVALID_OPTIONS: `type…rown for path: ['message'] and value: `undefined`"}
And:
Uncaught TypeError: Cannot read property 'unsubscribe' of undefined
at Modal.componentWillUnmount (Modal.js:93)
at callComponentWillUnmountWithTimer (react-dom.development.js:21896)
at HTMLUnknownElement.callCallback (react-dom.development.js:336)
at HTMLUnknownElement.sentryWrapped (helpers.ts:85)
at Object.invokeGuardedCallbackDev (react-dom.development.js:385)
at invokeGuardedCallback (react-dom.development.js:440)
at safelyCallComponentWillUnmount (react-dom.development.js:21903)
at commitUnmount (react-dom.development.js:22392)
at commitNestedUnmounts (react-dom.development.js:22486)
at unmountHostComponents (react-dom.development.js:22810)
at commitDeletion (react-dom.development.js:22896)
at commitMutationEffects (react-dom.development.js:25323)
at HTMLUnknownElement.callCallback (react-dom.development.js:336)
at HTMLUnknownElement.sentryWrapped (helpers.ts:85)
at Object.invokeGuardedCallbackDev (react-dom.development.js:385)
at invokeGuardedCallback (react-dom.development.js:440)
at commitRootImpl (react-dom.development.js:25050)
at unstable_runWithPriority (scheduler.development.js:697)
at runWithPriority$2 (react-dom.development.js:12149)
at commitRoot (react-dom.development.js:24922)
at finishSyncRender (react-dom.development.js:24329)
at performSyncWorkOnRoot (react-dom.development.js:24307)
at react-dom.development.js:12199
at unstable_runWithPriority (scheduler.development.js:697)
at runWithPriority$2 (react-dom.development.js:12149)
at flushSyncCallbackQueueImpl (react-dom.development.js:12194)
at flushSyncCallbackQueue (react-dom.development.js:12182)
at scheduleUpdateOnFiber (react-dom.development.js:23709)
at dispatchAction (react-dom.development.js:17076)
at Object.next (QueryData.ts:282)
at notifySubscription (Observable.js:135)
at onNotify (Observable.js:179)
at SubscriptionObserver.next (Observable.js:235)
at ObservableQuery.ts:701
at Array.forEach (<anonymous>)
at iterateObserversSafely (ObservableQuery.ts:701)
at Object.next (ObservableQuery.ts:662)
at invoke (QueryManager.ts:518)
at QueryManager.ts:644
at QueryManager.ts:1091
at Set.forEach (<anonymous>)
at QueryManager.ts:1087
at Map.forEach (<anonymous>)
at QueryManager.broadcastQueries (QueryManager.ts:1085)
at QueryManager.ts:1237
at Object.next (Observable.js:322)
at notifySubscription (Observable.js:135)
at onNotify (Observable.js:179)
at SubscriptionObserver.next (Observable.js:235)
at observables.ts:12
The Provider is sitting at the root of the project and looks like this:
import React, { useContext } from "react";
import {
Provider as AppBridgeProvider,
Loading,
TitleBar,
Context,
Modal
} from "@shopify/app-bridge-react";
import apolloClient from "./apollo";
import { ApolloProvider } from "react-apollo";
import enTranslations from "@shopify/polaris/locales/en.json";
import { AppProvider } from "@shopify/polaris";
import Router from "./Router";
const App: React.FC = () => {
const shopOrigin =
document.getElementById("shopify-app-init")!.dataset.shopOrigin || "";
const config = {
apiKey: "***************************8969",
shopOrigin: shopOrigin
};
return (
<ApolloProvider client={apolloClient}>
<AppProvider i18n={enTranslations}>
<AppBridgeProvider config={config}>
<Router></Router>
</AppBridgeProvider>
</AppProvider>
</ApolloProvider>
);
};
export default App;
And in the Router component:
import React from "react";
import { BrowserRouter } from "react-router-dom";
import Routes from "./Routes";
import { Context } from "@shopify/app-bridge-react";
export default function Router() {
return (
<BrowserRouter>
<Context.Consumer>
{app => {
// Do something with App Bridge `app` instance...
if (!app) {
return null;
}
return <Routes bridgeApp={app}></Routes>;
}}
</Context.Consumer>
</BrowserRouter>
);
}
The way the documentation for the Modal component is written, it seems as if you can just drop it in and have it work, but I haven’t had any luck getting it to happen so far.