Skip to content

RangeError: Maximum call stack size exceeded - Document Workaround? #205

@mmichaelis

Description

@mmichaelis

If "naively" creating custom tag mappings, you may run into this exception:

Uncaught RangeError: Maximum call stack size exceeded
    at Object.code (myHtml5Preset.ts:160:12)
    at myHtml5Preset.ts:72:72
    at k8 (utils.js:7:33)

To reproduce, create a tag-rule that generates "itself as child". For example, for parsing within CKEditor 5, we need to represent [code] as <pre><code>. If we naively adapt the code from HTML5 Preset for Blockquote:

quote: (node) => toNode('blockquote', {}, [toNode('p', {}, node.content)]),

We end up with a rule like this:

  code: (node) => toNode('pre', {}, [toNode('code', {}, node.content)]),

The problem: As parents are processed first, the newly created code will be processed afterward, so that we end up in an endless loop resulting in the RangeError given above.

Workaround:

As the above "naive mapping" may be a result of not fully understanding the internal processing in BBob, the suggestion is to actually "fix" this issue by documenting this possible workaround as "best-practice":

  code: (node) => toNode('pre', {}, [toNode('htmlCode', {}, node.content)]),
  htmlCode: (node) => toNode('code', {}, node.content),

This workaround tricks the processing order by creating an intermediate node htmlCode, that is resolved once the children of <pre> created by the original code rule are processed.

Metadata

Metadata

Assignees

Labels

P0Critical IssuebugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions