Skip to content

layoutDropcap: dcap.dcapjsStrut is not invalidated for dynamic content (ReactJS). #19

@umamialex

Description

@umamialex

Relevant code in question: https://github.com/adobe-webplatform/dropcap.js/blob/master/src/layout.js#L126-L140

Description:

The .dcapjsStrut property holding the cache of the strut <span> of the designated dropcap element (dcap in the code) is not invalidated in anyway on subsequent reruns of .layoutDropcap.

The outdated cache is a problem for reconciliation-based frameworks such as ReactJS. When new content is loaded into an application using dropcap.js, the dropcap's content and children are replaced, but the element itself stays the same. The lack of an actual strut <span> leads to expected bugs:

dropcap-bug

Here's the expected behaviour:

dropcap-expected

Workaround:

The current workaround is to set .dcapjsStrut of any dropcap elements to null before running Dropcap.layout().

Solution:

One solution would be to give a class to the strut <span>, and query the dropcap element for that instead of saving it as an attribute of the element. The class would be something like ._dropcap-strut and could even be a configurable option.

If that solution works, I'll gladly go ahead and make a PR for it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions