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

fix(headless): defensive code against clientID access from relay #4165

Merged
merged 1 commit into from
Jul 9, 2024
Merged
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
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
Loading