Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
umamialex opened this issue Jun 20, 2016 · 2 comments

Comments

@umamialex
Copy link

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!

umamialex added a commit to umamialex/suitupalex.com that referenced this issue Jun 20, 2016
* ContentManager, server, env: Separated production and preview keys.

* App, server, log: Added version logging.

* BlogPage, LandingPage: Added estimated read time.

* BlogPage, LandingPage: Only external links open in a new window.

* Router: Switched next and previous posts.

* BlogPage: Added styles for secondary headers.

* BlogPage: Added H2 styling.

* BlogPage, LandingPage: Added temporary workaround for dropcap issue adobe-webplatform/dropcap.js#19

* BlogPage: Updated dropcap styling.

* readme, license, package: Updated readme and license.

* package: Version bump.
@sylvain-galineau
Copy link
Contributor

My apologies for the delay and thank you for reporting this. I will try to fix this shortly.

@sylvain-galineau
Copy link
Contributor

I am not really familiar with React and the exact scenario you are mentioning; but it does sound that, even though the dropcap element is still there, the dcapjsStrut property points to a stale span that is no longer in the DOM. If so then I would expectdcapjsStrut.parentNode to be null or undefined. We could easily check for that. Is this something you could confirm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants