Skip to content

Commit 0ec320d

Browse files
committed
feat(overlay): Allow to skip sidecar
1 parent 86055cc commit 0ec320d

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

.changeset/bright-experts-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@spotlightjs/overlay': minor
3+
---
4+
5+
feat(overlay): Allow to skipSidecar to avoid connecting to sidecar

packages/overlay/src/App.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default function App({
2020
anchor,
2121
fullPage = false,
2222
showClearEventsButton = true,
23+
skipSidecar = false,
2324
}: AppProps) {
2425
const [integrationData, setIntegrationData] = useState<IntegrationData<unknown>>({});
2526
const [isOnline, setOnline] = useState(false);
@@ -46,8 +47,11 @@ export default function App({
4647
}, [integrations]);
4748

4849
useEffect(
49-
() => connectToSidecar(sidecarUrl, contentTypeToIntegrations, setIntegrationData, setOnline) as () => undefined,
50-
[sidecarUrl, contentTypeToIntegrations],
50+
() =>
51+
skipSidecar
52+
? () => {}
53+
: (connectToSidecar(sidecarUrl, contentTypeToIntegrations, setIntegrationData, setOnline) as () => undefined),
54+
[sidecarUrl, contentTypeToIntegrations, skipSidecar],
5155
);
5256

5357
const spotlightEventTarget = useMemo(() => getSpotlightEventTarget(), []);
@@ -62,6 +66,10 @@ export default function App({
6266
const eventHandlers = useMemo(() => {
6367
log('useMemo: initializing event handlers');
6468
const clearEvents = async () => {
69+
if (skipSidecar) {
70+
return;
71+
}
72+
6573
const { origin } = new URL(sidecarUrl);
6674
const clearEventsUrl: string = `${origin}/clear`;
6775

@@ -72,7 +80,7 @@ export default function App({
7280
});
7381
} catch (err) {
7482
console.error(
75-
`Spotlight can't connect to Sidecar is it running? See: https://spotlightjs.com/sidecar/npx/`,
83+
`Spotlight can't connect to Sidecar - is it running? See: https://spotlightjs.com/sidecar/npx/`,
7684
err,
7785
);
7886
return;
@@ -110,7 +118,7 @@ export default function App({
110118
};
111119

112120
return { clearEvents, onOpen, onClose, onNavigate, onToggle };
113-
}, [integrations, navigate, sidecarUrl]);
121+
}, [integrations, navigate, sidecarUrl, skipSidecar]);
114122

115123
useKeyPress(['ctrlKey', 'F12'], eventHandlers.onToggle);
116124

@@ -161,6 +169,7 @@ export default function App({
161169
integrationData={integrationData}
162170
setTriggerButtonCount={setTriggerButtonCount}
163171
fullPage={fullPage}
172+
skipSidecar={skipSidecar}
164173
showClearEventsButton={showClearEventsButton}
165174
/>
166175
</>

packages/overlay/src/components/Debugger.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default function Debugger({
4343
setTriggerButtonCount: setNotificationCount,
4444
fullPage,
4545
showClearEventsButton,
46+
skipSidecar,
4647
}: {
4748
integrations: Integration[];
4849
isOpen: boolean;
@@ -52,6 +53,7 @@ export default function Debugger({
5253
setTriggerButtonCount: (count: NotificationCount) => void;
5354
fullPage: boolean;
5455
showClearEventsButton: boolean;
56+
skipSidecar: boolean;
5557
}) {
5658
return (
5759
<FullscreenBlur isOpen={isOpen} setOpen={setOpen} fullPage={fullPage}>
@@ -80,17 +82,19 @@ export default function Debugger({
8082
<path d="M12 .3a12 12 0 0 0-3.8 23.38c.6.12.83-.26.83-.57L9 21.07c-3.34.72-4.04-1.61-4.04-1.61-.55-1.39-1.34-1.76-1.34-1.76-1.08-.74.09-.73.09-.73 1.2.09 1.83 1.24 1.83 1.24 1.08 1.83 2.81 1.3 3.5 1 .1-.78.42-1.31.76-1.61-2.67-.3-5.47-1.33-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.14-.3-.54-1.52.1-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6 0c2.28-1.55 3.29-1.23 3.29-1.23.64 1.66.24 2.88.12 3.18a4.65 4.65 0 0 1 1.23 3.22c0 4.61-2.8 5.63-5.48 5.92.42.36.81 1.1.81 2.22l-.01 3.29c0 .31.2.69.82.57A12 12 0 0 0 12 .3Z"></path>
8183
</svg>
8284
</a>
83-
<div
84-
className={classNames('ml-2 flex items-center gap-x-2 pl-2 text-xs', isOnline ? '' : 'text-red-400')}
85-
>
85+
{!skipSidecar && (
8686
<div
87-
className={classNames(
88-
' block h-2 w-2 rounded-full',
89-
isOnline ? 'bg-green-400' : 'animate-pulse bg-red-400',
90-
)}
91-
/>
92-
{isOnline ? 'Connected to Sidecar' : 'Not connected to Sidecar'}
93-
</div>
87+
className={classNames('ml-2 flex items-center gap-x-2 pl-2 text-xs', isOnline ? '' : 'text-red-400')}
88+
>
89+
<div
90+
className={classNames(
91+
' block h-2 w-2 rounded-full',
92+
isOnline ? 'bg-green-400' : 'animate-pulse bg-red-400',
93+
)}
94+
/>
95+
{isOnline ? 'Connected to Sidecar' : 'Not connected to Sidecar'}
96+
</div>
97+
)}
9498
</div>
9599
</h1>
96100
{showClearEventsButton && (

packages/overlay/src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export async function init({
9494
experiments = DEFAULT_EXPERIMENTS,
9595
fullPage = false,
9696
showClearEventsButton = true,
97+
skipSidecar = false,
9798
}: SpotlightOverlayOptions = {}) {
9899
// The undefined document guard is to avoid being initialized in a Worker
99100
// @see https://github.com/vitejs/vite/discussions/17644#discussioncomment-10026390
@@ -168,6 +169,7 @@ export async function init({
168169
anchor={anchor}
169170
fullPage={fullPage}
170171
showClearEventsButton={showClearEventsButton}
172+
skipSidecar={skipSidecar}
171173
/>
172174
</SpotlightContextProvider>
173175
</MemoryRouter>,

packages/overlay/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export type SpotlightOverlayOptions = {
9797
* @default true
9898
*/
9999
showClearEventsButton?: boolean;
100+
101+
/**
102+
* If set to `true`, the Spotlight overlay will not connect to the sidecar.
103+
* This is useful if you want to add data manually to Spotlight.
104+
*
105+
* @default false
106+
*/
107+
skipSidecar?: boolean;
100108
};
101109

102110
export type NotificationCount = {

0 commit comments

Comments
 (0)