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

refactor(@angular-devkit/build-angular): convert transformedContent into a function #24367

Merged
merged 1 commit into from Dec 2, 2022

Conversation

d3lm
Copy link
Contributor

@d3lm d3lm commented Dec 2, 2022

This PR converts transformedContent into a function to give more control when the readable stream is initialized. There might be issues with late "subscribers" where events are added after the readable stream was initialized and the data was already pushed, e.g.

const { rewriter } = await htmlRewritingStream('<div />');

setTimeout(() => {
  rewriter.on('startTag', (tag) => {
    console.log(tag);
  });
})

This will not work and potentially wait indefinitely. I have ran into such issue with WebContainer on stackblitz.com.

With this change the stream now needs to be explicitily initialized:

const { rewriter, transformedContent } = await htmlRewritingStream('<div />');

setTimeout(() => {
  rewriter.on('startTag', (tag) => {
    console.log(tag);
  });
  
  // calling this function will create the readable stream
  transformedContent();
})

This will work as expected.

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

…ive more control when the readable stream is initialized
@d3lm d3lm force-pushed the delm/fix/html-rewrite-stream branch from aea13fa to 5cc9654 Compare December 2, 2022 09:50
Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks @d3lm. Always great working with you :)

@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Dec 2, 2022
@alan-agius4 alan-agius4 self-assigned this Dec 2, 2022
@d3lm
Copy link
Contributor Author

d3lm commented Dec 2, 2022

Thanks @alan-agius4 Likewise! Always good to be able to contribute to Angular / Angular CLI.

@angular-robot angular-robot bot merged commit 65f78be into angular:main Dec 2, 2022
@d3lm d3lm deleted the delm/fix/html-rewrite-stream branch December 2, 2022 10:52
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants