Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Don't include args param in docs mode URL #14494

Merged
merged 2 commits into from Apr 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/api/src/modules/url.ts
Expand Up @@ -8,7 +8,6 @@ import { window } from 'global';
import { ModuleArgs, ModuleFn } from '../index';
import { PanelPositions } from './layout';
import { isStory } from '../lib/stories';
import type { Story } from '../lib/stories';

interface Additions {
isFullscreen?: boolean;
Expand Down Expand Up @@ -150,25 +149,30 @@ export const init: ModuleFn = ({ store, navigate, state, provider, fullAPI, ...r

const initModule = () => {
// Sets `args` parameter in URL, omitting any args that have their initial value or cannot be unserialized safely.
const updateArgsParam = (args?: Story['args']) => {
const updateArgsParam = () => {
const { path, viewMode } = fullAPI.getUrlState();
if (viewMode !== 'story') return;

const currentStory = fullAPI.getCurrentStoryData();
const initialArgs = (isStory(currentStory) && currentStory.initialArgs) || {};
if (!isStory(currentStory)) return;

const { args, initialArgs } = currentStory;
const argsString = buildArgsParam(initialArgs, args);
const argsParam = argsString.length ? `&args=${argsString}` : '';
queryNavigate(`${fullAPI.getUrlState().path}${argsParam}`, { replace: true });
queryNavigate(`${path}${argsParam}`, { replace: true });
api.setQueryParams({ args: argsString });
};

fullAPI.on(SET_CURRENT_STORY, () => updateArgsParam());

let handleOrId: any;
fullAPI.on(STORY_ARGS_UPDATED, ({ args }) => {
fullAPI.on(STORY_ARGS_UPDATED, () => {
if ('requestIdleCallback' in window) {
if (handleOrId) window.cancelIdleCallback(handleOrId);
handleOrId = window.requestIdleCallback(() => updateArgsParam(args), { timeout: 1000 });
handleOrId = window.requestIdleCallback(updateArgsParam, { timeout: 1000 });
} else {
if (handleOrId) clearTimeout(handleOrId);
setTimeout(updateArgsParam, 100, args);
setTimeout(updateArgsParam, 100);
}
});

Expand Down