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

Angular: Fix circular reference not being handled in moduleMetadata #15410

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"regenerator-runtime": "^0.13.7",
"sass-loader": "^10.1.0",
"strip-json-comments": "3.1.1",
"telejson": "^5.3.2",
"ts-dedent": "^2.0.0",
"ts-loader": "^8.0.14",
"tsconfig-paths-webpack-plugin": "^3.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { enableProdMode, NgModule, PlatformRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { BehaviorSubject, Subject } from 'rxjs';
import { stringify } from 'telejson';
import { ICollection, StoryFnAngularReturnType } from '../types';
import { Parameters } from '../types-6-0';
import { createStorybookModule, getStorybookModuleMetadata } from './StorybookModule';
Expand Down Expand Up @@ -160,7 +161,7 @@ export abstract class AbstractRenderer {

const currentStoryRender = {
storyFnAngular,
moduleMetadataSnapshot: JSON.stringify(moduleMetadata),
moduleMetadataSnapshot: stringify(moduleMetadata),
};

this.previousStoryRenderInfo = currentStoryRender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ describe('RendererService', () => {
);
});

it('should handle circular reference in moduleMetadata', async () => {
class Thing {
token: Thing;

constructor() {
this.token = this;
}
}
const token = new Thing();

await rendererService.render({
storyFnAngular: {
template: '🦊',
props: {},
moduleMetadata: { providers: [{ provide: 'foo', useValue: token }] },
},
forced: false,
parameters: {} as any,
});

expect(document.body.getElementsByTagName('storybook-wrapper')[0].innerHTML).toBe('🦊');
});

describe('when forced=true', () => {
beforeEach(async () => {
// Init first render
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { enableProdMode, NgModule, PlatformRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { BehaviorSubject, Subject } from 'rxjs';
import { stringify } from 'telejson';
import { ICollection, StoryFnAngularReturnType } from '../types';
import { Parameters } from '../types-6-0';
import { createStorybookModule, getStorybookModuleMetadata } from './StorybookModule';
Expand Down Expand Up @@ -154,7 +155,7 @@ export class RendererService {

this.currentStoryRender = {
storyFnAngular,
moduleMetadataSnapshot: JSON.stringify(moduleMetadata),
moduleMetadataSnapshot: stringify(moduleMetadata),
};

if (
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6170,6 +6170,7 @@ __metadata:
regenerator-runtime: ^0.13.7
sass-loader: ^10.1.0
strip-json-comments: 3.1.1
telejson: ^5.3.2
ts-dedent: ^2.0.0
ts-jest: ^26.4.4
ts-loader: ^8.0.14
Expand Down