Skip to content

Commit

Permalink
Revert "Docs: E2E tests for Source block update fix"
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Jun 6, 2023
1 parent 821e93a commit cf88e10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 46 deletions.
39 changes: 2 additions & 37 deletions code/e2e-tests/addon-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test.describe('addon-docs', () => {
test('should provide source snippet', async ({ page }) => {
// templateName is e.g. 'Vue-CLI (Default JS)'
test.skip(
/^(vue-cli|preact)/i.test(`${templateName}`),
/^(vue3|vue-cli|preact)/i.test(`${templateName}`),
`Skipping ${templateName}, which does not support dynamic source snippets`
);

Expand All @@ -111,6 +111,7 @@ test.describe('addon-docs', () => {

test('source snippet should not change in stories block', async ({ page }) => {
const skipped = [
'vue3',
'vue-cli',
'preact',
// SSv6 does not render stories in the correct order in our sandboxes
Expand Down Expand Up @@ -156,42 +157,6 @@ test.describe('addon-docs', () => {
await expect(storiesCode).toContainText('Basic');
});

test('source snippet should change back to previous value in stories block', async ({ page }) => {
test.skip(
/^(lit|vue-cli|preact|angular|internal\/ssv6|ca)/i.test(`${templateName}`),
`Skipping ${templateName}, which does not support dynamic source snippets`
);

const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docspage/basic', 'docs');
const root = sbPage.previewRoot();
const toggles = root.locator('.docblock-code-toggle');

const toggle = await toggles.nth(0);
await toggle.click({ force: true });

const codes = root.locator('pre.prismjs');

const code = await codes.nth(0);
const text = await code.innerText();

await expect(text).toContain('Basic');

const labelControl = root.locator('textarea[name=label]');
labelControl.fill('Changed');
labelControl.blur();

// Check the Primary one has changed
await expect(code).toContainText('Changed');

// Change the value back
labelControl.fill('Basic');
labelControl.blur();

// Check the Primary one has changed back
await expect(code).toContainText('Basic');
});

test('should not run autoplay stories without parameter', async ({ page }) => {
const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docspage/autoplay', 'docs');
Expand Down
19 changes: 10 additions & 9 deletions code/ui/blocks/src/blocks/SourceContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FC, Context, PropsWithChildren } from 'react';
import React, { createContext, useEffect, useState } from 'react';

import { dequal as deepEqual } from 'dequal';
import type { Channel } from '@storybook/channels';

import { SNIPPET_RENDERED } from '@storybook/docs-tools';
Expand Down Expand Up @@ -63,14 +64,11 @@ export const SourceContainer: FC<PropsWithChildren<{ channel: Channel }>> = ({
: idOrEvent;

const hash = args ? argsHash(args) : UNKNOWN_ARGS_HASH;
// FIXME: In SB8.0 when we remove the Source block deprecations,
// we should restore this optimizationand make the Source block
// smarter about understanding when its args change.
//
// See https://github.com/storybookjs/storybook/pull/22807
//
// optimization: don't update if the source is the same
// if (deepEqual(currentSource, { code: source, format })) return;

// optimization: if the source is the same, ignore the incoming event
if (sources[id] && sources[id][hash] && sources[id][hash].code === source) {
return;
}

setSources((current) => {
const newSources = {
Expand All @@ -81,7 +79,10 @@ export const SourceContainer: FC<PropsWithChildren<{ channel: Channel }>> = ({
},
};

return newSources;
if (!deepEqual(current, newSources)) {
return newSources;
}
return current;
});
};

Expand Down

0 comments on commit cf88e10

Please sign in to comment.