Skip to content

Change visibility of Readability::loadHtml() and prevent DOM reset in init() - #113

Merged
Kdecherf merged 3 commits into
j0k3r:masterfrom
Kdecherf:fix/loadHtml
Jul 11, 2026
Merged

Change visibility of Readability::loadHtml() and prevent DOM reset in init()#113
Kdecherf merged 3 commits into
j0k3r:masterfrom
Kdecherf:fix/loadHtml

Conversation

@Kdecherf

@Kdecherf Kdecherf commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

These changes are required for j0k3r/graby#392

@j0k3r @jtojnar commit 8f8fb2c introduces a slightly changed behavior on init().

With this PR, calling twice init() does not reset $dom anymore.
I don't know if you want to consider this as a breaking change.

@jtojnar

jtojnar commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

I think this should be fine. Nobody should be re-initing (re-executing really) a Readability instance. They should just make a new instance.

Do we know why it was moved in 66215a6? Could we perhaps just move it back? Though that might be a larger BC break than this.

Or alternately, move the HTML loading into a separate class and use it here and in Graby::getSinglePage(). Though that will not work for Graby\Extractor\ContentExtractor.

@j0k3r

j0k3r commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Do we know why it was moved in 66215a6?

Sadly, can't remember..

@Kdecherf

Copy link
Copy Markdown
Collaborator Author

Could we perhaps just move it back? Though that might be a larger BC break than this.

Yeah, moving back loadHtml() to __construct() may be a BC for those already using php-readability 2.x.
Also I triggered a different set of issues when trying this approach on my work for j0k3r/graby#392

I wonder if we shouldn't just go ahead and prevent init() to be called more than once

Comment thread src/Readability.php Outdated
@Kdecherf
Kdecherf requested a review from jtojnar June 30, 2026 20:55
@Kdecherf

Kdecherf commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

The changes view is a bit cluttered by the move of the loadHtml() function by php-cs-fixer, here is a shorter view of the actual changes: https://github.com/j0k3r/php-readability/pull/113/changes/BASE..3f9f3dc2efacad494c142ed735eef7719f508d30

@j0k3r

j0k3r commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Good move 👍🏼

Kdecherf added 3 commits July 11, 2026 21:37
This change is required for usecases where we want to load the DOM
without going through the whole init() process

Related to j0k3r/graby#392

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Letting init() resetting the DOM may lead to unexpected behaviors in
libraries like Graby.

Related to j0k3r/graby#392

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
@Kdecherf
Kdecherf merged commit a93488d into j0k3r:master Jul 11, 2026
11 checks passed
@Kdecherf
Kdecherf deleted the fix/loadHtml branch July 11, 2026 19:40
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

Successfully merging this pull request may close these issues.

3 participants