You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git clone https://github.com/jfcere/ngx-markdown.git
cd ngx-markdown
yarn install
yarn run start
Notice that the demo is already configured with the global CLIPBOARD_OPTIONS provider in app.config.ts.
Removing any [clipboardButtonComponent]="..." in any template will cause the clipboard button reverting to the default ClipboardButtonComponent not the globally provided component in app.config.ts.
Removing [clipboardButtonTemplate] will cause the same problem.
Description of the problem
In fact, none of clipboard enabled markdown components in the demo respects the globally defined buttonComponent.
NoticeMarkdownPipe doesn't suffer the same problem. e.g.
will respect the globally defined buttonComponent without supplying the same buttonComponent again.
This affects every version of ngx-markdown since the introduction of ClipboardJS.
Expected behaviour: When a buttonComponent is globally provided either by provideMarkdown or MarkdownModule.forRoot(), any clipboard enabled MarkdownComponent that didn't define their [clipboardButtonComponent] nor [clipboardButtonTemplate] should use the globally provided buttonComponent.
Alternatively if said problem was actually the expected behaviour, the injection token probably should be discarded or at least the pipe should have consistent behaviour with the component.
Here, value of this.clipboardOptions is from dependency injection which will be the globally defined CLIPBOARD_OPTIONS provided value.
Notice when clipboardOptions is undefined, clipboardOptions isn't going to override previous spreads since { ...{ foo: 'bar' }, ...undefined } = { foo: 'bar' }. However, when the clipboardOptions is non-empty, even it's properties were empty, e.g. { buttonComponent: undefined, buttonTemplate: undefined }, spreading it to the object would cause both properties be undefined since { ...{ foo: 'bar' }, ...{ foo: undefined }} = { foo: undefined }.
The MarkdownComponent is exactly the latter case and the MarkdownPipe is the former case.
Notice here, this.clipboardButtonComponent and this.clipboardButtonTemplate are both undefined when neither [clipboardButtonComponent] or [clipboardButtonTemplate] are provided. renderOptions is eventually passed down to MarkdownService.render():
In markdown.pipe.ts, since the options is passed in as a whole object, a consumer could simply choose to not define clipboardOptions property which avoids the described problem.
The text was updated successfully, but these errors were encountered:
Totally agree with the problem, it is currently impossible to use the global configuration in order to define a custom clipboard button.
I guess this could be debugged quite quickly, all the more since @robertjajajja did a quite deep exploration of the causes of the problem.
Steps to reproduce:
git clone https://github.com/jfcere/ngx-markdown.git cd ngx-markdown yarn install yarn run start
Notice that the demo is already configured with the global
CLIPBOARD_OPTIONS
provider inapp.config.ts
.Removing any
[clipboardButtonComponent]="..."
in any template will cause the clipboard button reverting to the defaultClipboardButtonComponent
not the globally provided component inapp.config.ts
.Removing
[clipboardButtonTemplate]
will cause the same problem.Description of the problem
In fact, none of clipboard enabled
markdown
components in the demo respects the globally definedbuttonComponent
.Notice
MarkdownPipe
doesn't suffer the same problem. e.g.will respect the globally defined
buttonComponent
without supplying the samebuttonComponent
again.This affects every version of
ngx-markdown
since the introduction ofClipboardJS
.Expected behaviour: When a
buttonComponent
is globally provided either byprovideMarkdown
orMarkdownModule.forRoot()
, any clipboard enabledMarkdownComponent
that didn't define their[clipboardButtonComponent]
nor[clipboardButtonTemplate]
should use the globally providedbuttonComponent
.Alternatively if said problem was actually the expected behaviour, the injection token probably should be discarded or at least the pipe should have consistent behaviour with the component.
Code analysis
In markdown.service.ts:
Here, value of
this.clipboardOptions
is from dependency injection which will be the globally definedCLIPBOARD_OPTIONS
provided value.Notice when
clipboardOptions
isundefined
,clipboardOptions
isn't going to override previous spreads since{ ...{ foo: 'bar' }, ...undefined }
={ foo: 'bar' }
. However, when theclipboardOptions
is non-empty, even it's properties were empty, e.g.{ buttonComponent: undefined, buttonTemplate: undefined }
, spreading it to the object would cause both properties beundefined
since{ ...{ foo: 'bar' }, ...{ foo: undefined }}
={ foo: undefined }
.The
MarkdownComponent
is exactly the latter case and theMarkdownPipe
is the former case.In markdown.component.ts:
Notice here,
this.clipboardButtonComponent
andthis.clipboardButtonTemplate
are bothundefined
when neither[clipboardButtonComponent]
or[clipboardButtonTemplate]
are provided.renderOptions
is eventually passed down toMarkdownService.render()
:caused the described problem.
In markdown.pipe.ts, since the
options
is passed in as a whole object, a consumer could simply choose to not defineclipboardOptions
property which avoids the described problem.The text was updated successfully, but these errors were encountered: