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

HTML API: Add test case to demonstrate issue with seeking after modifying #4355

Closed
wants to merge 1 commit into from

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Apr 20, 2023

In WordPress/block-interactivity-experiments#141, we found an issue with the Tag Processor that seems to be vaguely related to seeking after adding an attribute. We tried to distill this into a minimal test case for which @dmsnell found a fix in #4345.

Unfortunately, applying that fix to WordPress/block-interactivity-experiments#141 proved insufficient -- the issue persisted 😕

Part of the problem is that it’s fairly hard to reproduce issues that we’ve found in the wild (e.g. when running the Movies Demo against WordPress/block-interactivity-experiments#141). I’ve been moderately successful at isolating a somewhat scaled-down test there, which -- while still not fully capturing all issues -- at least fails even with #4345 applied. Unfortunately, it involves an extra class with a newly introduced class method 😕

I’ve decided to carry this test over to this repo so we have at least a baseline to try our fixes out with, even though it’s far from minimal for now.

Trac ticket: https://core.trac.wordpress.org/ticket/58160


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

dmsnell added a commit to dmsnell/wordpress-develop that referenced this pull request Apr 23, 2023
While working on WordPress/block-interactivity-experiments#141 @ockham
discovered that the Tag Processor was making a small mistake. After
making some updates the parser wasn't returning to the start of the
affected tag. A test case was created in WordPress#4355.

In few words, the Tag Processor has not been treating its own internal
pointer `bytes_already_parsed` the same way it treats its bookmarks.
That is, when updates are applied to the input document and then
`get_updated_html()` is called, the internal pointer transfers to
the newly-updated content as if no updates had been applied since
the previous call to `get_updated_html()`.

In this patch we're creating a new "shift accumulator" to account for
all of the updates that accrue before calling `get_updated_html()`.
This accumulated shift will be applied when swapping the input document
with the output buffer, which should result in the pointer pointing to
the same logical spot in the document it did before the udpate.

In effect this patch adds a single workaround for treating the
internal pointer like a bookmark, plus a temporary pointer which points
to the beginning of the current tag when calling `get_updated_html()`.
This will preserve the assumption that updating a document doesn't
move that pointer, or shift which tag is currently matched.
@ockham
Copy link
Contributor Author

ockham commented Apr 26, 2023

Closing this, as it has served its purpose. @dmsnell managed to distill this into a minimal test case, and fixed the underlying issue in #4371 🎉

@ockham ockham closed this Apr 26, 2023
@ockham ockham deleted the add/maximal-test-case branch April 26, 2023 08:25
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.

1 participant