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: styles not always applying correctly #314

Open
lgpage opened this issue Dec 18, 2022 · 3 comments
Open

bug: styles not always applying correctly #314

lgpage opened this issue Dec 18, 2022 · 3 comments

Comments

@lgpage
Copy link

lgpage commented Dec 18, 2022

This is a bit of an unusual one. When using a form control to set the value for the CodemirrorComponent the styles don't always apply correctly w.r.t. element sizes resulting in what looks like nothing being shown in the text area.

Template (snippet)

<form [formGroup]="formGroup">
  <ngx-codemirror
    formControlName="code"
  ></ngx-codemirror>
</form>

Component (snippet)

ngAfterViewInit(): void {
  this.formGroup.get('code')?.setValue(code);
  this.formGroup.updateValueAndValidity();
}

It is evident that the code has been added to the DOM
image

However the element sizes have not computed correctly
image

@lgpage
Copy link
Author

lgpage commented Dec 18, 2022

Relates to lgpage/rxtutor#212

@lgpage
Copy link
Author

lgpage commented Jan 6, 2023

Initially, I tried waiting for CodeMirror to load (within the CodeMirrorComponent) and then call cm.refresh() in the AfterViewInit hook (as per https://codemirror.net/5/doc/manual.html#refresh). This worked to some degree if I added a delay in the mix.
However, I noticed that when there was a delay in loading the styles, the code still appeared missing (I.e. the left margin still did not calculate correctly).

Eventually, I found this article https://0xdbe.github.io/AngularSecurity-DisableInlineCriticalCSS about Angulars (12+) optimization involving first inlining critical CSS and then delaying the loading of non-critical CSS. CodeMirrors CSS was contained within the non-critical CSS.

My guess is that to fix this issue (for said optimization), the critical parts of the CodeMirror CSS would need to be inlined within the index.html somehow.

My workaround was to set inlineCritical to false in angular.json as per the article above.

@aceleghin
Copy link

Same error, my workaround is to call cm.refresh() when I do focus in the codemirror but I disable some options like line number because seems not to apply correctly before I refresh

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

No branches or pull requests

2 participants