-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Rewriter trigger the "text" event even after the write callback is executed #1046
Comments
This is expected behavior in the rewriter: not all data will have been processed yet, and ending parsing will emit remaining data. Seems like there is an |
I've updated the comment to add the await |
@fb55 how can we get the remaining data if the event is not triggered? Is there a method that we are missing here? And even if there is a way, how can we avoid the event to be triggered? This event listener write the raw text back to the stream and crashes since the stream is considered as closed. |
The event is triggered, you just have to wait for the queue to clear. |
No, it wasn't really missing. Rewriter is a Node.js transform stream, and, like with any stream, users should be able to listen for As a more general comment, unless it's something minor like stylistic issue, please don't edit someone else's comments without discussing with the author :) |
Oh, I feel so stypid now. My IDE autocompletion didn't propose either Thanks a lot for your time and support. I should be able to handle the issue now. |
Glad it helped :) I removed the |
I wonder if it's because we export
|
Maybe, yes. But I would have assumed class and interface merging would trigger here. Still, compilation is fine because there is an
The only drawback is that we don't know at compile time what arguments do the listener accept. Still, for |
Right, I suspect that is the problem - our class inherits from I might be wrong but worth investigating. |
Consider the following code:
Executing it with node shows that the
rewritingStream.write
callback is executed before the secondtext
event listener is executed.I'm not sure it is expected or not - hence I hesitate to call this a bug - but it prevents the safe usage of @RReverser's solution to the #273 issue (#273 (comment)).
Note that it only happens with the
text
event and only when there is a text after the last close tag (or when there is not tag at all). It happens even is the text is a an empty string.Context
To give a little bit of context, we use the rewriter to rebase resources in HTML document based on the source map of that HTML document. The library that executes this rebasing is html-source-map-rebase. This is when writing tests for this library that we discovered the issue with the rewriter.
The text was updated successfully, but these errors were encountered: