Skip to content

Commit

Permalink
fix(headless): defensive code against clientID access from relay (#4165)
Browse files Browse the repository at this point in the history
  • Loading branch information
olamothe authored Jul 9, 2024
1 parent aa001e4 commit 26bf619
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/headless/src/app/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ function buildCoreEngine<
reducerManager.addCrossReducer(options.crossReducer);
}
const logger = thunkExtraArguments.logger;
const getClientId = () => {
let clientId = '';
try {
clientId = getRelayInstanceFromState(engine.state).getMeta('').clientId;
} catch (e) {
logger.warn('Error while obtaining clientID from relay', e);
}
return clientId;
};
const thunkExtraArgumentsWithRelay: CoreExtraArguments & ExtraArguments = {
...thunkExtraArguments,
get relay() {
Expand All @@ -301,9 +310,7 @@ function buildCoreEngine<
return defaultNodeJSNavigatorContextProvider();
}

return defaultBrowserNavigatorContextProvider(
getRelayInstanceFromState(engine.state).getMeta('').clientId
);
return defaultBrowserNavigatorContextProvider(getClientId());
},
};
const store = createStore(
Expand Down Expand Up @@ -350,9 +357,7 @@ function buildCoreEngine<
return defaultNodeJSNavigatorContextProvider();
}

return defaultBrowserNavigatorContextProvider(
getRelayInstanceFromState(engine.state).getMeta('').clientId
);
return defaultBrowserNavigatorContextProvider(getClientId());
},

logger,
Expand Down

0 comments on commit 26bf619

Please sign in to comment.