Skip to content

Remove Goerli (0x5) and dead environment toggle#263

Merged
0xferit merged 7 commits intodevelopfrom
copilot/fix-environment-always-dev
Mar 9, 2026
Merged

Remove Goerli (0x5) and dead environment toggle#263
0xferit merged 7 commits intodevelopfrom
copilot/fix-environment-always-dev

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

  • Remove Goerli (0x5) entries from both prod and dev configs in src/data/environments.js
  • Remove the dev environment entirely; export single environment config with only Mainnet, remove the isProd function and env var debug logs
  • Remove Goerli (0x5) entry from networkMap in src/data/ethereumProvider.jsx
  • Remove Goerli (0x5) entry from src/constants/blockExplorers.js
  • Fix hardcoded /0x5/ link in src/components/others/route_article/arbitrationDetails/index.jsx to use the current chain from route params
  • Validate URL chain against networkMap in src/index.jsx so unsupported chains (e.g. old /0x5/ bookmarks) fall back to the default network instead of crashing
  • Guard RouteRedirect against undefined/unsupported chainId to prevent crashes on legacy /0x5/... article/court/account URLs
  • Validate chain in all route loaders (Browse, Article, Court, Account) to redirect unsupported chains before data fetching
  • Verify the app builds successfully with parcel build
  • Run code review and CodeQL checks
Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: Environment always resolves to "dev" — Goerli set as default chain, hosted subgraph returns 301</issue_title>
<issue_description>## Summary

The deployed app at truthpost.news always runs in dev environment instead of prod. This means:

  • The default chain is 0x5 (Goerli) instead of 0x1 (Mainnet)
  • The Goerli subgraph endpoint (api.thegraph.com/subgraphs/name/proveuswrong/thetruthpost-goerli) returns HTTP 301 because The Graph's hosted service has been sunset

Navigating directly to /0x1/ still uses the correct mainnet subgraph (which works), so this issue is secondary to #260 for the /0x1/ route. However, it means:

  • Users landing on the root (/) get redirected to the Goerli chain by default
  • Any Goerli-related data fetches fail with 301
  • The console always prints Environment: dev

Root Cause

In src/data/environments.js, the isProd function checks Netlify build environment variables:

const isProd = (branchName, isPullRequest) => {
  if (!branchName || typeof isPullRequest == "undefined") return false;
  return (
    branchName === "main" ||
    branchName.startsWith("hotfix/") ||
    branchName.startsWith("release/") ||
    (branchName === "develop" && process.env.PULL_REQUEST === "true")
  );
};

export const selectedEnvironment = isProd(process.env.HEAD, process.env.PULL_REQUEST) ? "prod" : "dev";

In the compiled bundle, both process.env.HEAD and process.env.PULL_REQUEST are replaced with void 0 (undefined) by Parcel at build time. This means:

  • branchName is undefined
  • isProd immediately returns false
  • selectedEnvironment is always "dev"

You can verify this in the deployed bundle (index.45fae1d6.js):

xh=(kh=void 0,(Th=void 0)&&void 0!==kh&&("main"===Th||Th.startsWith("hotfix/")||Th.startsWith("release/"))?\"prod\":\"dev\")

Since Th = void 0, the && short-circuits and xh is always "dev".

Evidence

# Goerli hosted subgraph is dead (301 redirect)
$ curl -s -w "HTTP Status: %{http_code}" -X POST \
  -H "Content-Type: application/json" \
  -d '{"query":"{ _meta { block { number } } }"}' \
  "https://api.thegraph.com/subgraphs/name/proveuswrong/thetruthpost-goerli"
# HTTP Status: 301 (Moved Permanently)

# Mainnet studio subgraph works fine
$ curl -s -X POST -H "Content-Type: application/json" \
  -d '{"query":"{ _meta { block { number } } }"}' \
  "https://api.studio.thegraph.com/query/88965/thetruthpost/version/latest"
# {"data":{"_meta":{"block":{"number":24621644}}}}

Fix

Option A: Hardcode prod (simplest)

If this app is only deployed to production at truthpost.news, just remove the environment toggle:

- export const selectedEnvironment = isProd(process.env.HEAD, process.env.PULL_REQUEST) ? "prod" : "dev";
- export let environment = environments[selectedEnvironment];
+ export const selectedEnvironment = "prod";
+ export let environment = environments[selectedEnvironment];

Option B: Fix the Netlify env var injection

Ensure Parcel picks up HEAD and PULL_REQUEST during the Netlify build. This may require:

  • A .env file or Parcel plugin that injects these vars
  • Or switching to PARCEL_* prefixed env vars that Parcel auto-injects

Option C: Remove Goerli entirely

Goerli is deprecated (both the network itself and The Graph's hosted service for it). Remove the 0x5 entries from both prod and dev configs, and remove the dev environment entirely if there's no other testnet deployment.</issue_description>

<agent_instructions>Option C: Remove Goerli entirely</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 9, 2026 18:40
- Remove dev environment and Goerli entries from environments.js; export
  a single environment config with only Mainnet (0x1)
- Remove isProd function and Netlify env var debug logs
- Remove Goerli entry from networkMap in ethereumProvider.jsx
- Remove Goerli entry from blockExplorers.js
- Fix hardcoded /0x5/ link in arbitrationDetails to use current chain
  from route params

Co-authored-by: 0xferit <3106907+0xferit@users.noreply.github.com>
Co-authored-by: 0xferit <3106907+0xferit@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 9, 2026

Deploying webapp-tp with  Cloudflare Pages  Cloudflare Pages

Latest commit: ce6c283
Status:🚫  Build failed.

View logs

Copilot AI changed the title [WIP] Fix environment resolving to dev instead of prod Remove Goerli (0x5) and dead environment toggle Mar 9, 2026
@0xferit 0xferit requested a review from Copilot March 9, 2026 18:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes deprecated Goerli (0x5) support and the non-functional prod/dev environment toggle so the app consistently targets Mainnet and avoids dead hosted-subgraph endpoints.

Changes:

  • Simplified environment configuration to a single exported environment containing only Mainnet (0x1).
  • Removed Goerli entries from the in-app network map and block explorer constants.
  • Updated an arbitration “court” link to use the chain route param instead of hardcoding /0x5/.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/data/environments.js Collapses prod/dev configs into a single Mainnet-only environment.
src/data/ethereumProvider.jsx Removes Goerli from networkMap, leaving Mainnet-only chain support.
src/constants/blockExplorers.js Removes Goerli explorer URL mapping.
src/components/others/route_article/arbitrationDetails/index.jsx Fixes court link routing to respect the current chain param.
Comments suppressed due to low confidence (1)

src/data/ethereumProvider.jsx:18

  • After removing Goerli from networkMap, the app can still receive an unsupported chain ID from the URL (e.g. navigating directly to /0x5/...). EthereumProvider initializes chainId from chainIdFromUrl and handleChainChange only switches to a supported/default chain when !chainId, so an unsupported initial chainId will persist and later code paths that index networkMap[chainId] will throw. Consider validating chainIdFromUrl (or any existing chainId) against networkMap on initialization/chain changes and falling back to getDefaultNetwork() when unsupported (and/or redirecting the router accordingly).
export const networkMap = {
  "0x1": {
    name: "Ethereum Mainnet",
    shortname: "Mainnet",
    default: environment.networkMap["0x1"].default,
    explorerURL: (address) => `https://etherscan.io/address/${address}`,
    deployments: environment.networkMap["0x1"].deployments,
  },

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Member

@0xferit 0xferit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing networkMap["0x5"] leaves the router and provider accepting legacy /0x5/... URLs, but several code paths still index networkMap[chainId] without validating that the route chain is supported. In the PR head this can throw immediately for old/bookmarked Goerli URLs, because App still seeds chainId from any 0x* path segment, RouteRedirect dereferences networkMap[chainId].deployments, and EthereumProvider later does the same in its chainId effect.\n\nPlease add a fallback to getDefaultNetwork() (or redirect unsupported chains before these lookups) so removing Goerli support doesn’t turn existing /0x5/... links into a crash.

Validate the URL chain against networkMap before passing it to
EthereumProvider. Unsupported chains like 0x5 from old bookmarks
now resolve to undefined, letting EthereumProvider fall back to
the default network instead of crashing.

Co-authored-by: 0xferit <3106907+0xferit@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 9, 2026

Removing networkMap["0x5"] leaves the router and provider accepting legacy /0x5/... URLs, but several code paths still index networkMap[chainId] without validating that the route chain is suppor...

Fixed in db1cf53. The URL chain is now validated against networkMap in App before being passed to EthereumProvider:

const chainId = pathSegment.startsWith("0x") && networkMap[pathSegment] ? pathSegment : undefined;

Unsupported chains like /0x5/... from old bookmarks now resolve to undefined, so EthereumProvider falls back to getDefaultNetwork() (Mainnet) via the existing handleChainChange logic instead of crashing.

Copy link
Member

@0xferit 0xferit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new src/index.jsx guard fixes the top-level /0x5 case, but it still leaves legacy article/court/account URLs broken. For routes like /0x5/:contract/:id, App now passes undefined into EthereumProvider, and RouteRedirect immediately does Object.keys(networkMap[chainId].deployments) when params.contract is present. With chainId === undefined, that still throws before the app can redirect to mainnet.\n\nPlease either normalize unsupported route chains to the default network up front, or harden RouteRedirect against an undefined/unsupported chainId before dereferencing networkMap[chainId].

Copilot AI and others added 2 commits March 9, 2026 19:15
Add early return in RouteRedirect's useEffect when chainId is
undefined or not in networkMap. This prevents crashes on legacy
/0x5/... URLs where EthereumProvider hasn't yet resolved the
default network via handleChainChange.

Co-authored-by: 0xferit <3106907+0xferit@users.noreply.github.com>
Co-authored-by: 0xferit <3106907+0xferit@users.noreply.github.com>
Copy link
Member

@0xferit 0xferit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still two blockers on the current head:\n\n1. The unsupported-chain fallback is still bypassed by the route loaders. , , and loaders all pass directly into / / , and those helpers still dereference . So legacy and URLs can still fail during loader execution before or have a chance to normalize the chain.\n\n2. The latest commit also reintroduced and large unrelated churn. Unless this PR is intentionally changing package-manager artifacts, those lockfile changes should be removed before merge.

Copy link
Member

@0xferit 0xferit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still blocked on two points. First, the Browse, Article, and Court loaders still use params.chain directly before any RouteRedirect fallback runs, so legacy 0x5 routes can still fail during loader execution. Second, the last commit reintroduced package-lock.json and large unrelated yarn.lock churn, which should be removed unless this PR is intentionally changing package manager artifacts.

Copy link
Contributor Author

Copilot AI commented Mar 9, 2026

The new src/index.jsx guard fixes the top-level /0x5 case, but it still leaves legacy article/court/account URLs broken. For routes like /0x5/:contract/:id, App now passes undefined into `Et...

Fixed in 04a435e. Added an early return guard in RouteRedirect's useEffect:

if (!chainId || !networkMap[chainId]) return;

This prevents the networkMap[chainId].deployments dereference from throwing when chainId is still undefined (before EthereumProvider resolves the default network). Once the async handleChainChange sets chainId to the default, the effect re-runs with a valid chain and the redirect proceeds normally.

Copy link
Member

@0xferit 0xferit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring incidental improvements/package-manager churn per maintainer guidance. The remaining blocker is still the unsupported-chain loader path: browse/article/court loaders use params.chain directly, so legacy /0x5 URLs can still fail before the app-level fallback runs.

@0xferit 0xferit marked this pull request as ready for review March 9, 2026 19:19
Copy link
Member

@0xferit 0xferit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loader-level redirects now normalize unsupported chain routes before any networkMap lookup. Local production build passes.

@0xferit 0xferit merged commit 6363d99 into develop Mar 9, 2026
1 check failed
@0xferit 0xferit deleted the copilot/fix-environment-always-dev branch March 9, 2026 19:23
Copilot stopped work on behalf of 0xferit due to an error March 9, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Environment always resolves to "dev" — Goerli set as default chain, hosted subgraph returns 301

3 participants