Share Link Won't Open: Tracing a URL Parameter Placement Bug

11/18 2026 412

Series: "Writing High-Quality Code with AI: AI Werewolf Development Records" | Applies to version: v1.11.0 → v1.11.5 | Date: 2026-10-23

Preface

After Part 7 wrapped up the account system, the game finally "had an owner." The next priority: let other people see it.

I built a battle record card, a share panel, and a spectator link, and tested all three myself without a hitch. Then I sent the spectator link to a friend. He replied with a screenshot—the platform was reporting "incomplete link / current address is missing access parameters."

Intro: The only difference between the link that works and the one that doesn't is a #

I had sent out two things:

1. Battle record card—generated by "Save image / Share with friends" on the results page. My friend could open it.

2. Spectator link—the address obtained by tapping "Invite friends to watch" during a match. My friend could not open it.

Image: the battle record card on the results page. This is the one that opens normally—an image that doesn't depend on any parameter in the address.

Same code, same domain, same release. The only difference: the one that won't open is an address containing a # (#watch=…), while the one that opens isn't an address at all—it's an image.

This clue looks inconspicuous, but it narrowed the investigation from "the entire sharing feature" straight down to "links with #." The most valuable move in online troubleshooting is to put "the one that works" and "the one that doesn't" side by side and see where they diverge—faster than reading the code ten times over.

Problem: First, prove that "the server never received it"

The platform's error page only said "missing access parameters." It didn't say which one was missing, nor which part of the address was problematic. So instead of guessing, I ran a controlled experiment: same server, three requests.

Three curl commands that print only the status code: ① bare domain, ② with ?sharecode=…, ③ with ?sharecode=…#watch=abc.

The results: 403 / 200 / 200.

Conclusion in one sentence: without sharecode, it's 403. And ② and ③ produced exactly the same result—which is even more telling. It proves that the content after # didn't participate in the request at all; the server only ever saw ?sharecode=….

Cause: A URL has only two halves, and one half never reaches the server

Image: a URL splits into two halves. The query on the left is sent to the server with the request; the fragment on the right stays in the browser. The faulty version appended sharecode to the right half—so the request the server saw contained no such parameter at all, and it returned 403.

The only background you need is one sentence: # was originally designed for "in-page jump anchors," so it naturally belongs to browser-internal information. Even if you format what follows # exactly like a parameter, the server will never receive it.

How our code put the parameter in the wrong place

Generating the spectator link takes two steps: first build the deep link ${origin}/#watch=${gameId}, then call withShareCode(url, shareCode) to append the share code. The faulty withShareCode determined the separator solely by checking whether there was a question mark (url.includes('?') ? '&' : '?'), with no awareness of the hash at all. The whole string indeed had no ? (only #), so it appended directly with ?—the share code fell into the fragment, and the server received not a single character of it.

This isn't "one character written wrong"; it's that the function doesn't understand that addresses have structure. It treats the URL as a plain string, so it can only determine "whether there is a question mark," and cannot determine "whether the question mark is before or after the hash."

Solution: Three layers of handling, three actions

This fix wasn't "patch one step each time you hit a problem," but rather one fix per "which layer is wrong":

At generation: the parameter fell after # → ① make the function understand address boundaries. In the code: two implementations with the same name → ② keep only one. Regression: nothing stops it from coming back → ③ write the order as assertions.① At generation: the parameter must be inserted before #

The fixed implementation has only five steps: first split at #, taking the first half as base and the second half as hash; on base, decide whether to use & or ? based on "whether there is a ?" and append sharecode; finally concatenate hash back as-is (return as-is when there is no share code).

Parsing: the idea is just one sentence—first split at #, append the query to the "first half," then concatenate the hash back. This way, regardless of whether the original string has a # or what's inside the #, the parameter lands where the server can see it.

Note that sep still only looks at base (the part without #). Only by putting "judgment" and "concatenation" into the same function can it possibly be correct at the same time.

② In the code: keep only one function with the same name

Remove the duplicated handling logic in share.ts, and change it to import from url.ts and then re-export.

The value here isn't "a few fewer lines"—it's converging future changes to a single point. As long as two copies exist, there will inevitably come a time when "one copy was changed and the other was forgotten." And this incident proved exactly that: the copy in url.ts actually also failed to handle #; it was just that nobody took that path.

③ Regression: write the order as assertions

Changing the code isn't the end; something must stop it from coming back. So AI was then asked to add 7 test cases for verification.

Effect: opening in a fresh session returns 200

The link generated after the fix looks like this:

https:///?sharecode=2IBHTRFFFL#watch=gmvknynr5d64f93

?sharecode=… comes first, #watch=… comes after. I pasted it into a brand-new incognito window: HTTP 200, the spectator page loaded all 6 seats normally, and the progress updated in real time.

Summary

1. In online troubleshooting, find the control group first: where the working one and the non-working one differ, and the scope immediately shrinks by half. Three curl commands are more useful than reading code for an hour.

2. Keeping two copies of a function with the same name is equivalent to planting a future "missed change" for yourself. This time neither copy handled #; it was just that only one path happened to hit it.

3. Is it transferable? It applies to any product with deep links (# routing), invite parameters, or tracking parameters—this is the most common type of "environment knowledge" in frontend work.

Solemnly declare: the copyright of this article belongs to the original author. The reprinted article is only for the purpose of spreading more information. If the author's information is marked incorrectly, please contact us immediately to modify or delete it. Thank you.