Skip to content

Commit a4448e5

Browse files
authored
[ENG-3672] Explain and fix a Patchstack widget that appears twice (#80)
Adds an "I see two Patchstack widgets" section to the JavaScript / Node.js troubleshooting page: where the second copy comes from (a hand-added tag, a same-site page shown in an <iframe>, a React effect that runs twice), how the widget now keeps one launcher per page on its own, a console count to check the live page, and a paste-ready prompt for the site builder's AI. Companion to sass-webvdp-widget #112. Ref ENG-3672
1 parent c0e89c0 commit a4448e5

1 file changed

Lines changed: 52 additions & 3 deletions

File tree

‎src/content/docs/Getting Started/Installing Patchstack/troubleshooting-javascript-node-projects.mdx‎

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
title: "Troubleshooting JavaScript / Node.js projects"
3-
excerpt: "Fix a disclosure widget that never appears, a published build that serves an old integration, a broken config file, or an outdated @patchstack/connect — including prompts to paste into an AI site builder."
3+
excerpt: "Fix a disclosure widget that never appears or appears twice, a published build that serves an old integration, a broken config file, or an outdated @patchstack/connect — including prompts to paste into an AI site builder."
44
hidden: false
55
createdAt: "Mon Sep 07 2026 00:00:00 GMT+0000 (Coordinated Universal Time)"
6-
updatedAt: "Mon Sep 07 2026 00:00:00 GMT+0000 (Coordinated Universal Time)"
6+
updatedAt: "Wed Sep 09 2026 00:00:00 GMT+0000 (Coordinated Universal Time)"
77
sidebar:
88
order: 7.4
99
label: "Troubleshooting JS / Node.js"
1010
---
1111

1212
import { Steps, Aside } from '@astrojs/starlight/components';
1313

14-
This page covers the problems that come up after connecting a JavaScript or Node.js project with [`@patchstack/connect`](/getting-started/installing-patchstack/installing-on-javascript-node-projects/): a disclosure widget that never appears, a published site still serving an old integration, a build that broke after a config change, and a connector stuck on an old version.
14+
This page covers the problems that come up after connecting a JavaScript or Node.js project with [`@patchstack/connect`](/getting-started/installing-patchstack/installing-on-javascript-node-projects/): a disclosure widget that never appears, a widget that appears twice, a published site still serving an old integration, a build that broke after a config change, and a connector stuck on an old version.
1515

1616
Every section ends with a **prompt you can paste into your site builder's AI chat**. The prompts are deliberately explicit about proving the result, because builder assistants otherwise tend to report the version they remember, or stop after editing one file.
1717

@@ -205,6 +205,55 @@ Please diagnose and fix the Patchstack build after the config-file update.
205205
Please complete and verify the fix. Thank you.
206206
```
207207

208+
## I see two Patchstack widgets
209+
210+
Two shield buttons stacked in the corner, sometimes one opening the owner log-in and the other the report form, mean the widget script ran twice on that page. They often sit on exactly the same pixel, so the second one only shows when a panel opens or the layout shifts.
211+
212+
The widget keeps **one floating launcher per page** on its own:
213+
214+
- A second copy loaded by the **same document** is ignored, with a `[PatchstackWidget]` warning in the browser console.
215+
- A copy inside a page of **your own site that the shell shows in an `<iframe>`** stands down as well, with a console message. The connector's `mark-build` step stamps every built HTML file, so an embedded static page carries the tag too; that copy is harmless and you can leave it.
216+
217+
What still needs your attention is a second tag that you, or the builder's AI, added by hand. It usually lives in a component, a layout, or a runtime `useEffect` that appends the script. Keep exactly one tag, in the root shell.
218+
219+
<Aside type="note" title="React StrictMode">
220+
In development React runs effects twice. A snippet that appends the widget `<script>` in `useEffect` must call `destroy()` on the widget in its cleanup, or the first copy survives. The React snippet in the [widget integration guide](https://cdn.patchstack.com/llm.html) does this.
221+
</Aside>
222+
223+
Count the copies on the published page from the browser console:
224+
225+
```js
226+
document.querySelectorAll('script[src*="patchstack-widget"]').length // want 1
227+
document.querySelectorAll('#patchstack-widget-host').length // want 1
228+
```
229+
230+
If the page embeds another page of your site in an `<iframe>`, run the same two lines inside that frame (pick it in the console's context dropdown). One host in the shell and none in the frame is the expected result.
231+
232+
### Prompt: two widgets on the page
233+
234+
```text
235+
Please make sure the Patchstack widget is loaded exactly once on this site.
236+
237+
1. Search the entire project - source files, layouts, components, and static
238+
HTML under public/ - for "patchstack-widget.js" and list every place that
239+
loads it.
240+
2. Keep exactly one <script> tag: the connector-managed one in the root shell
241+
(index.html, or the root layout for Next.js / TanStack Start / Remix). It
242+
must carry data-site-uuid with the value from the committed
243+
.patchstackrc.json.
244+
3. Remove every other copy that was added by hand: in components, in layouts,
245+
and in code that appends the script at runtime. If a component must load it
246+
at runtime, call destroy() on the returned widget in the effect cleanup.
247+
4. Leave the tag that @patchstack/connect writes into static HTML pages during
248+
mark-build; the widget ignores it when that page is shown inside the shell.
249+
5. Run the complete production build, publish it, open the live site, and
250+
confirm a single launcher is visible and the browser console shows no
251+
"[PatchstackWidget] A floating widget is already on this page" warning.
252+
253+
Please make the changes and show me the list from step 1 and the console
254+
check from step 5. Thank you.
255+
```
256+
208257
## Still stuck?
209258

210259
- `npx @patchstack/connect guide` prints a project-aware checklist of what is present and what is missing.

0 commit comments

Comments
 (0)