Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion code/core/src/manager-api/modules/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ export const init: ModuleFn<SubAPI, SubState> = (moduleArgs) => {
base === 'origin' ? originAddress : base === 'network' ? networkAddress : pathname;
const previewBase = refId
? refs[refId].url + '/iframe.html'
: global.PREVIEW_URL || `${managerBase.replace(/\/[^/]*$/, '/')}iframe.html`;
: global.PREVIEW_URL ||
`${managerBase.replace(/\/[^/]*\.html$/, '').replace(/\/?$/, '/')}iframe.html`;

const refParam = refId ? `&refId=${encodeURIComponent(refId)}` : '';
const { args = '', globals = '', ...otherParams } = queryParams;
Expand Down
45 changes: 45 additions & 0 deletions code/core/src/manager-api/tests/url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,49 @@ describe('getStoryHrefs', () => {
expect(managerHref).toEqual('/index.html?path=/story/test--story');
expect(previewHref).toEqual('/iframe.html?id=test--story&viewMode=story');
});

it('correctly links when hosted at a subpath without trailing slash', () => {
const { api, state } = initURL({
store,
provider: { channel: new EventEmitter() },
state: { location: { pathname: '/design-system', search: '' } },
navigate: vi.fn(),
fullAPI: { getCurrentStoryData: () => ({ id: 'test--story' }) },
});
store.setState(state);

const { managerHref, previewHref } = api.getStoryHrefs('test--story');
expect(managerHref).toEqual('/design-system?path=/story/test--story');
expect(previewHref).toEqual('/design-system/iframe.html?id=test--story&viewMode=story');
});

it('correctly links when hosted at a subpath with trailing slash', () => {
const { api, state } = initURL({
store,
provider: { channel: new EventEmitter() },
state: { location: { pathname: '/design-system/', search: '' } },
navigate: vi.fn(),
fullAPI: { getCurrentStoryData: () => ({ id: 'test--story' }) },
});
store.setState(state);

const { managerHref, previewHref } = api.getStoryHrefs('test--story');
expect(managerHref).toEqual('/design-system/?path=/story/test--story');
expect(previewHref).toEqual('/design-system/iframe.html?id=test--story&viewMode=story');
});

it('correctly links when hosted at a subpath with index.html', () => {
const { api, state } = initURL({
store,
provider: { channel: new EventEmitter() },
state: { location: { pathname: '/design-system/index.html', search: '' } },
navigate: vi.fn(),
fullAPI: { getCurrentStoryData: () => ({ id: 'test--story' }) },
});
store.setState(state);

const { managerHref, previewHref } = api.getStoryHrefs('test--story');
expect(managerHref).toEqual('/design-system/index.html?path=/story/test--story');
expect(previewHref).toEqual('/design-system/iframe.html?id=test--story&viewMode=story');
});
});
Loading