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

Debugging client side exceptions on Vercel #10658

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ require('./env');
const { REWRITES } = require('./rewrites');

const nextConfig = {
swcMinify: false, // Disable SWC minification
productionBrowserSourceMaps: true,
eslint: { ignoreDuringBuilds: true },
useFileSystemPublicRoutes: true,
productionBrowserSourceMaps: true,
typescript: {
ignoreBuildErrors: true,
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"@radix-ui/react-focus-scope": "^1.0.4"
},
"scripts": {
"build": "npm-run-all build:updates build:next build:server",
"build": "next build",
"build:e2e": "cross-env NODE_ENV=development OC_ENV=e2e npm run build",
"build:clean": "shx rm -rf dist .next",
"build:components": "npm run publish-components -- --build-only",
Expand All @@ -163,7 +163,7 @@
"depcheck": "npx @opencollective/depcheck",
"deploy:production": "cross-env ./scripts/pre-deploy.sh production && git push production main",
"deploy:staging": "cross-env ./scripts/pre-deploy.sh staging && git push -f staging main",
"dev": "node server",
"dev": "next dev",
"docs:generate:contribution-flow": "tsx ./scripts/docs/contribution-flow.js",
"git:clean": "cross-env ./scripts/git_clean.sh",
"graphql:codegen": "graphql-codegen --config scripts/config/graphql-codegen.ts",
Expand Down
37 changes: 16 additions & 21 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import memoizeOne from 'memoize-one';

import { APOLLO_STATE_PROP_NAME, initClient } from '../lib/apollo-client';
import { getTokenFromCookie } from '../lib/auth';
import { getGoogleMapsScriptUrl, loadGoogleMaps } from '../lib/google-maps';
import { loggedInUserQuery } from '../lib/graphql/v1/queries';
import LoggedInUser from '../lib/LoggedInUser';
import { withTwoFactorAuthentication } from '../lib/two-factor-authentication/TwoFactorAuthenticationContext';
Expand Down Expand Up @@ -81,27 +80,27 @@ class OpenCollectiveFrontendApp extends App {
ctx.req.apolloClient = apolloClient;
}

const props = { pageProps: { skipDataFromTree: true }, scripts: {}, ...getIntlProps(ctx) };
const props = { pageProps: { skipDataFromTree: true }, ...getIntlProps(ctx) };

try {
if (Component.getInitialProps) {
props.pageProps = await Component.getInitialProps({ ...ctx });
}

if (props.pageProps.scripts) {
if (props.pageProps.scripts.googleMaps) {
if (ctx.req) {
props.scripts['google-maps'] = getGoogleMapsScriptUrl();
} else {
try {
await loadGoogleMaps();
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
}
}
}
// if (props.pageProps.scripts) {
// if (props.pageProps.scripts.googleMaps) {
// if (ctx.req) {
// props.scripts['google-maps'] = getGoogleMapsScriptUrl();
// } else {
// try {
// await loadGoogleMaps();
// } catch (e) {
// // eslint-disable-next-line no-console
// console.error(e);
// }
// }
// }
// }
} catch (error) {
return { ...props, hasError: true, errorEventId: sentryLib.captureException(error, ctx) };
}
Expand Down Expand Up @@ -167,7 +166,7 @@ class OpenCollectiveFrontendApp extends App {
});

render() {
const { Component, pageProps, scripts, locale, LoggedInUserData } = this.props;
const { Component, pageProps, locale, LoggedInUserData } = this.props;

if (
typeof window !== 'undefined' &&
Expand All @@ -177,7 +176,6 @@ class OpenCollectiveFrontendApp extends App {
// eslint-disable-next-line no-console
console.log('pageProps apollo cache', pageProps?.[APOLLO_STATE_PROP_NAME]);
}

return (
<Fragment>
<ApolloProvider
Expand Down Expand Up @@ -209,9 +207,6 @@ class OpenCollectiveFrontendApp extends App {
</ThemeProvider>
</ApolloProvider>
<DefaultPaletteStyle palette={defaultColors.primary} />
{Object.keys(scripts).map(key => (
<script key={key} type="text/javascript" src={scripts[key]} />
))}
</Fragment>
);
}
Expand Down
21 changes: 15 additions & 6 deletions pages/create-collective.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';

Check failure on line 1 in pages/create-collective.js

View workflow job for this annotation

GitHub Actions / lint

Run autofix to sort these imports!
import PropTypes from 'prop-types';
import { useQuery } from '@apollo/client';
import { useRouter } from 'next/router';
Expand All @@ -10,7 +10,8 @@
import ErrorPage from '../components/ErrorPage';
import Page from '../components/Page';
import { withUser } from '../components/UserProvider';

import { getGoogleMapsScriptUrl } from '../lib/google-maps';
import Script from 'next/script';
const createCollectiveHostQuery = gql`
query CreateCollectiveHost($slug: String!) {
host(slug: $slug) {
Expand Down Expand Up @@ -53,15 +54,23 @@
return (
<Page showFooter={Boolean(LoggedInUser)}>
<CreateCollective host={data && data.host} />
<Script
src={getGoogleMapsScriptUrl()}
strategy="lazyOnload" // Loads the script lazily on client-side
onLoad={() => {
console.log('Google Maps script loaded successfully');

Check failure on line 61 in pages/create-collective.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}}
/>
</Page>
);
};

CreateCollectivePage.getInitialProps = () => {
return {
scripts: { googleMaps: true }, // To enable location autocomplete
};
};
// CreateCollectivePage.getInitialProps = () => {
// const googleMapsUrl = getGoogleMapsScriptUrl();
// return {
// scripts: { googleMaps: true }, // To enable location autocomplete
// };
// };

CreateCollectivePage.propTypes = {
loadingLoggedInUser: PropTypes.bool.isRequired,
Expand Down
19 changes: 14 additions & 5 deletions pages/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';

Check failure on line 1 in pages/dashboard.tsx

View workflow job for this annotation

GitHub Actions / lint

Run autofix to sort these imports!
import { useQuery } from '@apollo/client';
import { clsx } from 'clsx';
import { useRouter } from 'next/router';
Expand Down Expand Up @@ -34,6 +34,8 @@
import Page from '../components/Page';
import SignInOrJoinFree from '../components/SignInOrJoinFree';
import { TwoFactorAuthRequiredMessage } from '../components/TwoFactorAuthRequiredMessage';
import Script from 'next/script';
import { getGoogleMapsScriptUrl } from '../lib/google-maps';

const messages = defineMessages({
collectiveIsArchived: {
Expand Down Expand Up @@ -293,15 +295,22 @@
</Page>
<Footer />
</div>
<Script
src={getGoogleMapsScriptUrl()}
strategy="lazyOnload" // Loads the script lazily on client-side
onLoad={() => {
console.log('Google Maps script loaded successfully');

Check failure on line 302 in pages/dashboard.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}}
/>
</DashboardContext.Provider>
);
};

DashboardPage.getInitialProps = () => {
return {
scripts: { googleMaps: true }, // TODO: This should be enabled only for events
};
};
// DashboardPage.getInitialProps = () => {
// return {
// scripts: { googleMaps: true }, // TODO: This should be enabled only for events
// };
// };

// next.js export
// ts-unused-exports:disable-next-line
Expand Down
Loading