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

Vue: Add repro template for vue-cli #19165

Merged
merged 37 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e757728
Vue: Add repro templates for vue-cli
shilman Sep 11, 2022
33a1d7d
Merge branch 'next' into shilman/vue-cli-repro-templates
shilman Sep 11, 2022
5f220b6
Vue-cli: Don't nuke cwd on init
shilman Sep 11, 2022
7e84537
Escape vue-cli vue2 preset properly
shilman Sep 11, 2022
06d885a
Vue2: Add template components for sandbox
shilman Sep 12, 2022
19f25e0
Merge branch 'next' into shilman/vue-cli-repro-templates
shilman Sep 13, 2022
3dbf5f6
CLI/Vue3: Upgrade vue-loader and install `@vue/compiler-sfc`
shilman Sep 13, 2022
60f1aa5
Vue: Fix typo in template Button
shilman Sep 13, 2022
55f4668
Merge branch 'next' into shilman/vue-cli-repro-templates
shilman Sep 14, 2022
10cfadd
Try fix missing typescript in JS-only project
shilman Sep 14, 2022
05dfc5c
Apply the same fix for vue3 webpack preset
shilman Sep 14, 2022
ac16a23
Vue3: Fix babel / ts-loader both run against .ts files
shilman Sep 14, 2022
fde61fc
Revert "Apply the same fix for vue3 webpack preset"
tmeasday Sep 14, 2022
024e8a7
Revert "Try fix missing typescript in JS-only project"
tmeasday Sep 14, 2022
2dc7254
Exclude all rules from template-stories
tmeasday Sep 14, 2022
48e3af9
Vue: Add Form/Html template components
shilman Sep 14, 2022
b8380fa
Vue2: Fix play's within(canvas) by preserving `#storybook-root`
shilman Sep 15, 2022
1aa24c9
Update snapshots
shilman Sep 15, 2022
70fc932
Don't run source snippet e2e on vue-cli's vue3
shilman Sep 15, 2022
1036cbc
Addon-a11y: Fix template stories
shilman Sep 15, 2022
398dadc
Vue: Fixed Pre template component
shilman Sep 15, 2022
7e7bffb
Fix skip logic for vue-cli snippet test
shilman Sep 15, 2022
5dbe451
Fix duplicate import
shilman Sep 15, 2022
5ef1742
Added Vue2 DOM breaking change to MIGRATION guide
shilman Sep 15, 2022
7571d14
CLI: Don't add babel dependencies
shilman Sep 15, 2022
cb4b205
Fix stories
shilman Sep 15, 2022
000e6a1
Actions/Interactions: Identify actions by isAction to fix production …
shilman Sep 16, 2022
18709fc
Task: Prefix chromatic junit keys with templateKey
shilman Sep 16, 2022
e957951
Merge branch 'next' into shilman/vue-cli-repro-templates
shilman Sep 16, 2022
b9add15
Vue: Disable Vue2 repro template until rendering is fixed
shilman Sep 17, 2022
b613372
Fix location of store manual title story
shilman Sep 17, 2022
150cf37
Skip story re-rendering test for vue3/svelte
shilman Sep 17, 2022
e5de18d
Fix typo
shilman Sep 17, 2022
4857588
Scripts: Prefix junit into base task runner
shilman Sep 17, 2022
c2042c3
fix typo
shilman Sep 17, 2022
aa3a8ea
Revert "Vue2: Fix play's within(canvas) by preserving `#storybook-root`"
shilman Sep 18, 2022
1034ba9
Revert "Added Vue2 DOM breaking change to MIGRATION guide"
shilman Sep 18, 2022
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
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 8
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -497,7 +497,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 8
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -513,7 +513,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 8
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -533,7 +533,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 8
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -549,7 +549,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 7
parallelism: 8
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -565,7 +565,7 @@ jobs:
executor:
class: medium+
name: sb_playwright
parallelism: 7
parallelism: 8
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand Down
9 changes: 8 additions & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
- [Vite builder uses vite config automatically](#vite-builder-uses-vite-config-automatically)
- [Removed docs.getContainer and getPage parameters](#removed-docsgetcontainer-and-getpage-parameters)
- [Icons API changed](#icons-api-changed)
- ['config' preset entry replaced with 'previewAnnotations'](#config-preset-entry-replaced-with-preview-annotations)
- ['config' preset entry replaced with 'previewAnnotations'](#config-preset-entry-replaced-with-previewannotations)
- [Vue2 DOM structure changed](#vue2-dom-structure-changed)
- [Docs Changes](#docs-changes)
- [Standalone docs files](#standalone-docs-files)
- [Referencing stories in docs files](#referencing-stories-in-docs-files)
Expand Down Expand Up @@ -550,6 +551,12 @@ The preset field `'config'` has been replaced with `'previewAnnotations'`. `'con

Additionally, the internal field `'previewEntries'` has been removed. If you need a preview entry, just use a `'previewAnnotations'` file and don't export anything.

#### Vue2 DOM structure changed

In 6.x, `@storybook/vue` would replace the "root" element (formerly `#root`, now `#storybook-root`) with a new node that contains the rendered children. This was problematic because it broke the `play` function, which often starts with `within(canvasElement)` and the old `canvasElement` would get replaced out from under the play function.

In 7.0, `@storybook/vue` now leaves `#storybook-root` alone, and creates a new "dummy node" called `#storybook-vue-root` beneath it. This will break DOM snapshots moving from 6.5 to 7.0, but shouldn't have any other negative effects.

### Docs Changes

The information hierarchy of docs in Storybook has changed in 7.0. The main difference is that each docs is listed in the sidebar as a separate entry, rather than attached to individual stories.
Expand Down
4 changes: 2 additions & 2 deletions code/addons/a11y/template/stories/parameters.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import globalThis from 'global';
export default {
component: globalThis.Components.Html,
args: {
contents: '<button>Click Me!</button>',
content: '<button>Click Me!</button>',
},
parameters: {
chromatic: { disable: true },
Expand All @@ -12,7 +12,7 @@ export default {

export const Options = {
args: {
contents:
content:
'<button style="color: rgb(255, 255, 255); background-color: rgb(76, 175, 80);">Click me!</button>',
},
parameters: {
Expand Down
6 changes: 3 additions & 3 deletions code/addons/a11y/template/stories/tests.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import globalThis from 'global';
export default {
component: globalThis.Components.Html,
args: {
contents: '',
content: '',
},
parameters: {
chromatic: { disable: true },
Expand All @@ -12,7 +12,7 @@ export default {

export const Violations = {
args: {
contents: `
content: `
<div>
<p>empty heading</p>
<h1></h1>
Expand All @@ -39,7 +39,7 @@ export const Violations = {

export const Passes = {
args: {
contents: `
content: `
<div>
<p>heading</p>
<h1>heading 1</h1>
Expand Down
1 change: 1 addition & 0 deletions code/addons/actions/src/preview/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function action(name: string, options: ActionOptions = {}): HandlerFuncti
};
channel.emit(EVENT_ID, actionDisplayToEmit);
};
handler.isAction = true;

return handler;
}
2 changes: 1 addition & 1 deletion code/addons/interactions/src/preset/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const addSpies = (id: string, val: any, key?: string): any => {
if (Array.isArray(val)) {
return val.map((item, index) => addSpies(id, item, `${key}[${index}]`));
}
if (typeof val === 'function' && val.name === 'actionHandler') {
if (typeof val === 'function' && val.isAction) {
ghengeveld marked this conversation as resolved.
Show resolved Hide resolved
Object.defineProperty(val, 'name', { value: key, writable: false });
Object.defineProperty(val, '__storyId__', { value: id, writable: false });
const spy = action(val);
Expand Down
3 changes: 2 additions & 1 deletion code/e2e-tests/addon-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ test.describe('addon-docs', () => {
});

test('should provide source snippet', async ({ page }) => {
// templateName is e.g. 'Vue-CLI (Default JS)'
test.skip(
/^vue3/.test(templateName),
/^(vue3|vue-cli)/i.test(templateName),
`Skipping ${templateName}, which does not support dynamic source snippets`
);

Expand Down
12 changes: 4 additions & 8 deletions code/frameworks/vue-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
};
};

export const typescript = async (
config: StorybookConfig['typescript']
): Promise<StorybookConfig['typescript']> => {
return {
...config,
skipBabel: true,
};
};
export const typescript: PresetProperty<'typescript', StorybookConfig> = async (config) => ({
...config,
skipBabel: true,
});
5 changes: 5 additions & 0 deletions code/frameworks/vue3-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
},
};
};

export const typescript: PresetProperty<'typescript', StorybookConfig> = async (config) => ({
...config,
skipBabel: true,
});
2 changes: 1 addition & 1 deletion code/lib/cli/src/generators/VUE3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Generator } from '../types';

const generator: Generator = async (packageManager, npmOptions, options) => {
await baseGenerator(packageManager, npmOptions, options, 'vue3', {
extraPackages: ['vue-loader@^16.0.0'],
extraPackages: ['vue-loader@^17.0.0', '@vue/compiler-sfc@^3.2.0'],
});
};

Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/src/generators/baseGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const defaultOptions: FrameworkOptions = {
staticDir: undefined,
addScripts: true,
addComponents: true,
addBabel: true,
addBabel: false,
addESLint: false,
extraMain: undefined,
framework: undefined,
Expand Down
28 changes: 28 additions & 0 deletions code/lib/cli/src/repro-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,39 @@ const svelteViteTemplates = {
// }
};

const vueCliTemplates = {
'vue-cli/default-js': {
name: 'Vue-CLI (Default JS)',
script: 'npx -p @vue/cli vue create . --default --packageManager=yarn --force --merge',
cadence: ['ci', 'daily', 'weekly'],
expected: {
framework: '@storybook/vue3-webpack5',
renderer: '@storybook/vue3',
builder: '@storybook/builder-webpack5',
},
},
//
// FIXME: https://github.com/storybookjs/storybook/issues/19204
//
// 'vue-cli/vue2-default-js': {
// name: 'Vue-CLI (Vue2 JS)',
// script:
// 'npx -p @vue/cli vue create . --default --packageManager=yarn --force --merge --preset=Default\\ (Vue\\ 2)',
// cadence: ['ci', 'daily', 'weekly'],
// expected: {
// framework: '@storybook/vue-webpack5',
// renderer: '@storybook/vue',
// builder: '@storybook/builder-webpack5',
// },
// },
};

export default {
...craTemplates,
...reactViteTemplates,
...vue3ViteTemplates,
...svelteViteTemplates,
...vueCliTemplates,
// FIXME: missing documentation.json
// 'angular/latest': {
// name: 'Angular (latest)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Object {
"include": Array [
"ROOT",
],
"test": "/\\\\.(mjs|tsx?|jsx?)$/",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just a snapshot update, but was the removal of tsx intentional?

"test": "/\\\\.(mjs|jsx?)$/",
"use": Array [
Object {
"loader": "NODE_MODULES/babel-loader/lib/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Object {
"include": Array [
"ROOT",
],
"test": "/\\\\.(mjs|tsx?|jsx?)$/",
"test": "/\\\\.(mjs|jsx?)$/",
"use": Array [
Object {
"loader": "NODE_MODULES/babel-loader/lib/index.js",
Expand Down
6 changes: 5 additions & 1 deletion code/lib/store/template/stories/rendering.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ export const ForceReRender = {

export const ChangeArgs = {
play: async ({ canvasElement, id }: PlayFunctionContext) => {
// const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
const button = await within(canvasElement).findByRole('button');
await button.focus();
await expect(button).toHaveFocus();

// Vue3: https://github.com/storybookjs/storybook/issues/13913
// Svelte: https://github.com/storybookjs/storybook/issues/19205
if (['vue3', 'svelte'].includes(globalThis.storybookRenderer)) return;

// When we change the args to the button, it should not rerender
await channel.emit('updateStoryArgs', { storyId: id, updatedArgs: { children: 'New Text' } });
await within(canvasElement).findByText(/New Text/);
Expand Down
2 changes: 1 addition & 1 deletion code/lib/store/template/stories/title.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PlayFunctionContext } from '@storybook/csf';

export default {
component: globalThis.Components.Pre,
title: 'manual title',
title: 'lib/store/manual title',
args: { text: 'No content' },
};

Expand Down
1 change: 1 addition & 0 deletions code/renderers/react/template/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import { Form } from './Form.jsx';
import { Html } from './Html.jsx';

globalThis.Components = { Button, Pre, Form, Html };
globalThis.storybookRenderer = 'vue';
1 change: 1 addition & 0 deletions code/renderers/svelte/template/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import Form from './Form.svelte';
import Html from './Html.svelte';

globalThis.Components = { Button, Pre, Form, Html };
globalThis.storybookRenderer = 'svelte';
19 changes: 12 additions & 7 deletions code/renderers/vue/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { VueFramework } from './types';
export const COMPONENT = 'STORYBOOK_COMPONENT';
export const VALUES = 'STORYBOOK_VALUES';

const map = new Map<Element, Instance>();
const map = new Map<Element, [Instance, Element]>();
type Instance = CombinedVueInstance<
Vue,
{
Expand All @@ -21,11 +21,16 @@ type Instance = CombinedVueInstance<
Record<never, any>,
unknown
>;
const getRoot = (domElement: Element): Instance => {
const getRoot = (domElement: Element): [Instance, Element] => {
if (map.has(domElement)) {
return map.get(domElement);
}

// Create a dummy "target" underneath #storybook-root
// that Vue2 will replace on first render with #storybook-vue-root
const target = document.createElement('div');
domElement.appendChild(target);

const instance = new Vue({
beforeDestroy() {
map.delete(domElement);
Expand All @@ -37,13 +42,13 @@ const getRoot = (domElement: Element): Instance => {
};
},
render(h) {
map.set(domElement, instance);
map.set(domElement, [instance, target]);
const children = this[COMPONENT] ? [h(this[COMPONENT])] : undefined;
return h('div', { attrs: { id: 'storybook-root' } }, children);
return h('div', { attrs: { id: 'storybook-vue-root' } }, children);
},
});

return instance;
return [instance, target];
};

export const render: ArgsStoryFn<VueFramework> = (props, context) => {
Expand Down Expand Up @@ -92,7 +97,7 @@ export function renderToDOM(
}: RenderContext<VueFramework>,
domElement: Element
) {
const root = getRoot(domElement);
const [root, target] = getRoot(domElement);
Vue.config.errorHandler = showException;
const element = storyFn();

Expand All @@ -116,7 +121,7 @@ export function renderToDOM(
root[VALUES] = { ...element.options[VALUES], ...args };

if (!map.has(domElement)) {
root.$mount(domElement);
root.$mount(target);
}

showMain();
Expand Down
Loading