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

[do not merge] Introduce extra requests on the initial path of the app #10621

Closed
wants to merge 7 commits into from
Closed
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
37 changes: 35 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ import "../src/global-css";
import "../src/test-prep";
import "../src/base.css";

if (typeof window !== "undefined") {
Promise.prototype.finally = function (callback) {
return this.then(
result => {
callback && callback();
return result;
},
result => {
callback && callback();
throw result;
}
);
};
}

interface AuthProps {
apiKey?: string;
}
Expand All @@ -36,7 +51,25 @@ function Routing({ Component, pageProps, accessToken }: AppProps & { accessToken
const { getFeatureFlag } = useLaunchDarkly();

useEffect(() => {
bootstrapApp(accessToken).then(setStore);
// @ts-ignore
async function fetchAndLog(url: string): any {
const response = await fetch(url);
const json = await response.json();
console.log(json);
return json;
}
async function init() {
const store = await bootstrapApp(accessToken)

try {
const response = await fetchAndLog('https://swapi.dev/api/people');
await fetchAndLog(response.next)
} catch {}

setStore(store)
}

init()
}, [accessToken]);

if (!store) {
Expand Down Expand Up @@ -156,4 +189,4 @@ App.getInitialProps = (appContext: AppContext) => {
return { ...props, ...authProps };
};

export default App;
export default App;
2 changes: 1 addition & 1 deletion pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const csp = (props: any) => {
// localhost:8000 for prod to support the ?dispatch parameter when running
// the local backend
"http://localhost:* http://*.replay.local ws://*.replay.local ws://localhost:*"
}`,
} https://swapi.dev`,
`frame-src replay: https://js.stripe.com https://hooks.stripe.com https://${authHost} https://www.loom.com/`,
// Required by some of our external services
`script-src 'self' 'unsafe-eval' https://cdn.lr-ingest.io https://cdn.lr-in.com https://js.stripe.com ${hash}`,
Expand Down
Loading