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

Simplify API for streaming and fix unmatchable bug #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

7rulnik
Copy link

@7rulnik 7rulnik commented Mar 15, 2020

We can simplify API for users by hiding pipe inside of createStyleStream/createCriticalStyleStream. So users will just wrap React stream with our function. So the whole render process becomes simpler because we don't need multistream dep and also it's easier to catch errors because now we forward error from React stream.

I don't understand your idea with block rendering (I don't understand what headerStream stands for) so it's kinda hard to update usage in this block.

Also, I can make it with backward capability but not sure that it worth it.

And there is a problem with extractAllUnmatchableAsString. It didn't wrap css into style tag. I fixed it in this PR, but I can create another one for it.

image

@7rulnik 7rulnik changed the title WIP: simplify API for streaming Simplify API for streaming and fix unmatchable bug Mar 16, 2020
@7rulnik 7rulnik force-pushed the feature/simplify-streaming-api branch from bf18808 to d81d884 Compare March 16, 2020 00:26
@@ -73,4 +74,11 @@ export const createCriticalStyleStream = (def: StyleDefinition) => {
cb(undefined, line.tail);
}
});

reactStream.on('error', err => {
Copy link
Owner

Choose a reason for hiding this comment

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

this might be an important moment.

@@ -14,8 +14,8 @@ input { display: none; }
`;

exports[`React css stream React.renderToStream 1`] = `
"input { color: rightInput; }
<style type=\\"text/css\\" data-used-styles=\\"file1,file2\\">.a,
"<style type=\\"text/css\\" data-used-styles=\\"true\\">input { color: rightInput; }
Copy link
Owner

Choose a reason for hiding this comment

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

was it a bug?

@@ -106,8 +106,9 @@ export const extractAllUnmatchable = kashe((def: StyleDefinition): StyleChunk[]
));

export const extractAllUnmatchableAsString = kashe((def: StyleDefinition) => (
extractAllUnmatchable(def)
.reduce((acc, {css}) => acc + css, '')
wrapInStyle(
Copy link
Owner

Choose a reason for hiding this comment

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

So this is a 🐛!

@theKashey
Copy link
Owner

  • 👍 I like how easier is use your API
  • 👎 I don't like breaking API change and less flexibility - the same could be done by exposing one command (like "combine")

PS: It would be very good to have a bug fix a separate PR to publish it without any delay.

@theKashey
Copy link
Owner

Hey! I've updated underlaying tools and updated tslint/prettier caused some conflicts :(
I've also fixed the extractAllUnmatchableAsString bug you've discovered 🙇

@7rulnik
Copy link
Author

7rulnik commented Mar 23, 2020

You stole my contribution :D
Okay, I will rewrite it to combine function as we discussed

@sayjeyhi
Copy link

sayjeyhi commented Apr 2, 2020

@theKashey I thought @7rulnik is right about simplifying of API without using multistream. as it seems it did not maintained any more. in other hand it is hard to start using used-styles for now cuz of complexity.

@sayjeyhi
Copy link

sayjeyhi commented Apr 2, 2020

I thought there is not much usage of this library for now and breaking API change is not big deal.

@7rulnik
Copy link
Author

7rulnik commented Apr 2, 2020

We discussed a bit this idea with @theKashey. He wants to save flexibility of api (for example, you can pipe into used-styles directly). I agree with him so I will introduce combine function that will simplify usage of used-styles.

Somethin like that:

combine(reactStream, usedStylesStream)

@7rulnik
Copy link
Author

7rulnik commented Jun 17, 2022

@theKashey looks like it could be revived :D Also maybe we need some changes to adopt it for React 18

@theKashey
Copy link
Owner

👋 hey, there is a good time to break API in some way to support #40. That would require internal API to become a little bit more abstract so one can build more specific code on top of.

So can you clarify what exactly you are looking for and let's do it.

some changes to adopt it for React 18

I've used used-styles for React 18 in "old good rendering mode" with no issues (and there could be none), but I am really not sure how to support the "new rendering mode".
A broken test would be appreciated.

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.

None yet

3 participants