@dfosco/storyboard 0.6.10 → 0.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -132,6 +132,14 @@ function matchStoryRoute(pathname) {
|
|
|
132
132
|
* Strip the app's sub-path prefix (e.g. /storyboard) from the pathname.
|
|
133
133
|
* React Router's basename strips the branch prefix but not the app name prefix
|
|
134
134
|
* when the app runs under a nested base path.
|
|
135
|
+
*
|
|
136
|
+
* Two prefixing scenarios are handled:
|
|
137
|
+
* 1. Branch deploys — BASE_URL is `/branch--xxx/{devDomain}/`, so we strip
|
|
138
|
+
* whatever app sub-path remains after the branch prefix.
|
|
139
|
+
* 2. Local dev via Caddy proxy — BASE_URL is `/` (Caddy strips `/{devDomain}/`
|
|
140
|
+
* before forwarding to the dev server), but window.location.pathname is
|
|
141
|
+
* still `/{devDomain}/...`. React Router's basename `/` doesn't strip it,
|
|
142
|
+
* so we rely on the injected `__SB_DEV_DOMAIN__` global instead.
|
|
135
143
|
*/
|
|
136
144
|
function stripBasePath(pathname) {
|
|
137
145
|
let p = pathname.replace(/\/+$/, '') || '/'
|
|
@@ -146,6 +154,18 @@ function stripBasePath(pathname) {
|
|
|
146
154
|
p = p.slice(subPath.length) || '/'
|
|
147
155
|
}
|
|
148
156
|
}
|
|
157
|
+
// Local dev via Caddy proxy: window.location.pathname includes the
|
|
158
|
+
// /{devDomain}/ prefix that Caddy strips before reaching the dev server.
|
|
159
|
+
// BASE_URL is `/` in this scenario, so the block above is a no-op.
|
|
160
|
+
if (typeof window !== 'undefined' && window.__SB_LOCAL_DEV__ && window.__SB_DEV_DOMAIN__) {
|
|
161
|
+
const devDomain = String(window.__SB_DEV_DOMAIN__).replace(/^\/+|\/+$/g, '')
|
|
162
|
+
if (devDomain) {
|
|
163
|
+
const devPrefix = '/' + devDomain
|
|
164
|
+
if (p === devPrefix || p.startsWith(devPrefix + '/')) {
|
|
165
|
+
p = p.slice(devPrefix.length) || '/'
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
149
169
|
return p
|
|
150
170
|
}
|
|
151
171
|
|
|
@@ -293,4 +293,51 @@ describe('StoryboardProvider', () => {
|
|
|
293
293
|
expect(screen.getByText('Canvas not found')).toBeInTheDocument()
|
|
294
294
|
expect(screen.getByRole('link', { name: /go to index page/i })).toHaveAttribute('href', '/')
|
|
295
295
|
})
|
|
296
|
+
|
|
297
|
+
it('strips dev-domain prefix in local dev (Caddy proxy) so canvas routes resolve', () => {
|
|
298
|
+
// Local dev via Caddy: window.location.pathname includes the /{devDomain}/
|
|
299
|
+
// prefix even though BASE_URL is `/` (the proxy strips it before forwarding
|
|
300
|
+
// to the dev server). Without stripping, isCanvasPath returns false and the
|
|
301
|
+
// 404 never renders — the canvas page just stays blank.
|
|
302
|
+
const origLocalDev = window.__SB_LOCAL_DEV__
|
|
303
|
+
const origDomain = window.__SB_DEV_DOMAIN__
|
|
304
|
+
window.__SB_LOCAL_DEV__ = true
|
|
305
|
+
window.__SB_DEV_DOMAIN__ = 'storyboard'
|
|
306
|
+
try {
|
|
307
|
+
mockUseLocation.mockReturnValue({ pathname: '/storyboard/canvas/unknown-board', search: '', hash: '' })
|
|
308
|
+
|
|
309
|
+
render(
|
|
310
|
+
<StoryboardProvider>
|
|
311
|
+
<ContextReader />
|
|
312
|
+
</StoryboardProvider>,
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
expect(screen.getByText('Canvas not found')).toBeInTheDocument()
|
|
316
|
+
} finally {
|
|
317
|
+
window.__SB_LOCAL_DEV__ = origLocalDev
|
|
318
|
+
window.__SB_DEV_DOMAIN__ = origDomain
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
it('does not strip dev-domain prefix when __SB_LOCAL_DEV__ is not set', () => {
|
|
323
|
+
// Same URL shape, but production-like: prefix should be left alone so it
|
|
324
|
+
// doesn't accidentally match canvas routes for unrelated path segments.
|
|
325
|
+
const origDomain = window.__SB_DEV_DOMAIN__
|
|
326
|
+
window.__SB_DEV_DOMAIN__ = 'storyboard'
|
|
327
|
+
try {
|
|
328
|
+
mockUseLocation.mockReturnValue({ pathname: '/storyboard/canvas/unknown-board', search: '', hash: '' })
|
|
329
|
+
|
|
330
|
+
render(
|
|
331
|
+
<StoryboardProvider>
|
|
332
|
+
<ContextReader />
|
|
333
|
+
</StoryboardProvider>,
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
// isCanvasPath sees `/storyboard/canvas/...` → does NOT start with `/canvas/`
|
|
337
|
+
// → no 404, just renders flow context
|
|
338
|
+
expect(screen.queryByText('Canvas not found')).not.toBeInTheDocument()
|
|
339
|
+
} finally {
|
|
340
|
+
window.__SB_DEV_DOMAIN__ = origDomain
|
|
341
|
+
}
|
|
342
|
+
})
|
|
296
343
|
})
|