[Pages] Header and footer content leak between editor instances
Affected Packages
@tiptap-pro/extension-pages, @tiptap-pro/extension-pages-pagekit
Tiptap Version
0.28.4
Browser Used
Chrome
What happened?
When one Pages editor is destroyed and another Pages editor is created, the new editor can render the previous editor's header and footer. This is for the case of read-only, meaning for the editor:
editable: false,and for PageKit
editableHeader: false,
editableFooter: false,We have the error when navigating: open a page with some content. Navigate away. Navigate to the same page again but with another content.
https://github.com/user-attachments/assets/c261dcab-945d-41d0-8df8-8b9d40b473ab
The first editor contains a header. It is unmounted and destroyed before the second editor is created.
The second editor is configured with an empty header and footer. Its Pages storage correctly reports:
header: ""
footer: ""However, its freshly created storage contains the previous editor's normalized values:
normalizedHeaderTemplate:
"<p ...>FIRST DOCUMENT HEADER</p>"
normalizedFooterTemplate:
"<p ...>FIRST DOCUMENT FOOTER</p>"The previous header is then displayed in the second editor.
The main document content belongs to the second editor, so only the header/footer state is stale.
The editor lifecycle appears to complete correctly. The first editor's onDestroy callback runs before the second editor is mounted.
In the attached video, you will see that the header appeared during few frames before being removed. We expected to see the header.
Expected Behavior
Each editor instance should derive its header and footer only from its own Pages configuration.
When a new editor is configured with header: "" and footer: "", no content from a previously destroyed editor should be rendered or copied into its Pages storage.
Destroying an editor should leave no cached header or footer content that can affect a later editor instance.
Reproducible Example URL (Optional)
No response
Additional Context (Optional)
This was originally observed while reviewing sequential DOCX imports, but the import API returns the correct values. The problem occurs after the values are passed to Pages. Configuration:
- Main editor is read-only.
editableHeaderisfalse.editableFooterisfalse.- Collaboration is not enabled.
- The first editor is destroyed before the second editor is created.
- A full page reload clears the stale value.
- The problem occurs when editor instances are created sequentially in the same browser page.
Based on debugging the distributed @tiptap-pro/extension-pages code, this appears related to module-level page configuration caching.
The cache identity is derived from layout properties such as page format, margins, page gap, and page-gap background. The cached configuration also contains the default header and footer. A later editor using the same layout can therefore receive header/footer values from the previous cached configuration.
This is only a suspected cause, but it matches the storage values and observed rendering.
Source: ueberdosis/tiptap