Skip to content

Commit

Permalink
feat: allow to suppress global register warnings
Browse files Browse the repository at this point in the history
useful for server side rendering where all customModules/customOptions are registered twice (1x in mock env on server side, 1x on client side)
  • Loading branch information
KillerCodeMonkey committed May 3, 2020
1 parent 716a5b9 commit cd22cd4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export { renderModule, renderModuleFactory } from '@angular/platform-server';
The `quill-editor` and `quill-view` component of ngx-quill are doing the rest for you to check, if it is running on server- or browser side.
On server-side both components will not render or do anything, because they depend on QuillJS and so on the real browser environment.

**Hint:** Set `suppressGlobalRegisterWarning: true` in the global config to suppress quilljs warnings.

If you want to render your html content of the editor for seo purposes check out the `quill-view-html` component, that simply renders the html content :).

## Global Config
Expand Down Expand Up @@ -228,6 +230,14 @@ The `QuillModule` exports the `defaultModules` if you want to extend them :).
- use customOptions for adding for example custom font sizes or other options/formats
- use customModules for adding and overwriting modules, e.g. image-resize or your own modules

### Suppress global register warnings

Per default when `Quill.register` is called and you are overwriting an already existing module, QuillJS logs a warning. If you pass `customOptions` or `customModules` ngx-quill is registering those modules/options/formats for you.

In e.g. an angular univeral project your `AppModule` and so `QuillModule.forRoot()` is executed twice (1x server side, 1x browser). QuillJS is running in a mocked env on server side, so it is intendet that every register runs twice.

To subpress those expected warnings you can turn them off by passing `suppressGlobalRegisterWarning: true`.

## QuillEditorComponent

### Hint
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ngx-quill",
"license": "MIT",
"version": "9.1.1",
"version": "9.2.0",
"author": {
"name": "Bengt Weiße"
},
Expand Down
2 changes: 1 addition & 1 deletion src/quill-editor.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ describe('QuillEditor - base config', () => {
}).providers
}).compileComponents()

expect(registerSpy).toHaveBeenCalledWith('modules/custom', CustomModule)
expect(registerSpy).toHaveBeenCalledWith('modules/custom', CustomModule, undefined)
})

it('renders editor with config', async () => {
Expand Down
1 change: 1 addition & 0 deletions src/quill-editor.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface QuillConfig {
bounds?: HTMLElement | string
customModules?: CustomModule[]
customOptions?: CustomOption[]
suppressGlobalRegisterWarning?: boolean
debug?: 'error' | 'warn' | 'log' | false
format?: QuillFormat
formats?: string[]
Expand Down
4 changes: 2 additions & 2 deletions src/quill.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class QuillModule {
config.customOptions?.forEach((customOption) => {
const newCustomOption = Quill.import(customOption.import)
newCustomOption.whitelist = customOption.whitelist
Quill.register(newCustomOption, true)
Quill.register(newCustomOption, true, config.suppressGlobalRegisterWarning)
})

config.customModules?.forEach(({implementation, path}) => {
Quill.register(path, implementation)
Quill.register(path, implementation, config.suppressGlobalRegisterWarning)
})

// set default modules as modules if not modules key passed on custom config
Expand Down

0 comments on commit cd22cd4

Please sign in to comment.