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

[Bug] Iframe not rendered correctly when displaying different files from a gist in seperate ngx-gist components #6

Closed
ekkolon opened this issue Feb 6, 2023 · 0 comments · Fixed by #7

Comments

@ekkolon
Copy link
Owner

ekkolon commented Feb 6, 2023

Describe the bug
When trying to render a gist containing multiple files in seperate ngx-gist components,
the iframes are just partially rendered.

For example:

// example-page.component.ts

@Component({
 templateUrl: './example-page.component.html'
})
export class ExamplePage {
 gistId = "05151ac90b51a5d3a0c3e85cb942a456"
}
// example-page.component.html

<div class="ngx-gist-embed-single-file">
 <ngx-gist [gistId]="gistId" file="ngx_gist_embed_example_2.py"></ngx-gist>
</div>

<div class="ngx-gist-embed-all-files">
 <ngx-gist [gistId]="gistId"></ngx-gist>
</div>

Expected behavior
Expected both iframes to render the whole content while automatically adjusting the iframe's height.

Screenshots

ngx-gist-iframe-rendering-error

Traceback

This layout error may be caused by using the same iframe id for both ngx-gist components
when the component computes property bindings:

/**
* The id of the gist to display.
*/
@Input() set gistId(id: string) {
this._gistId = id;
this._iframeId = `gist-${id}`;
}

Since each fragment of a gist varies in size/height, iframe-resizer cannot calculate each individual component's height properly. This is because each iframe's height is calculated per id, resulting in stopping calculating other iframes with the same id.

Possible solution

To get around this issue, we need to append the filename (if provided) to the generated iframeId.

For example:

...

  /**
   * The file to display. If not specified, the first file in the gist will be displayed.
   */
  @Input() file?: string;

  /**
   * The id of the gist to display.
   */
  @Input() set gistId(id: string) {
    this._gistId = id;
    const fileId = this.file ? `-file=${this.file}` : ''`
    this._iframeId = `gist-${id}${fileId}`;
  }

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant