Comments (10)
For those still using the example styled-components
. This can be used with the react 18 streaming example:
const styleSheet = new ServerStyleSheet();
// SSR render the full App
const { pipe, abort } = renderToPipeableStream(
styleSheet.collectStyles(
<RemixServer
context={remixContext}
url={request.url}
abortDelay={ABORT_DELAY}
/>
),
{
// use onShellReady to wait until a suspense boundary is triggered
onShellReady() {
responseHeaders.set("Content-Type", "text/html");
const body = new PassThrough({
transform: (chunk, _, done) => {
// perform previous behaviour and replace the "__STYLES__" placeholder as it's streamed to the client
const stringChunk = (chunk as Buffer).toString();
done(
undefined,
Buffer.from(
stringChunk.replace("__STYLES__", styleSheet.getStyleTags())
)
);
},
});
pipe(body);
resolve(
new Response(body, {
status: didError ? 500 : responseStatusCode,
headers: responseHeaders,
})
);
},
onShellError(err: unknown) {
reject(err);
},
onError(err: unknown) {
didError = true;
console.error(err);
},
}
);
Seems to be working so far for me!
from examples.
@AxelBriche I'm working on a PR to update all examples to be in line with our templates.
@kiliman
styled-components
has an issue about HTML streaming: styled-components/styled-components#3658
It seems they have documented how to implement a working example with streaming rendering:
https://styled-components.com/docs/advanced#streaming-rendering
However, it uses the deprecated renderToNodeStream
, not sure how to use it with renderToPipeableStream
This does not also not work with a streamed response though.
from examples.
@AxelBriche I'm working on a PR to update all examples to be in line with our templates.
@kiliman styled-components
has an issue about HTML streaming: styled-components/styled-components#3658
from examples.
A pull request updating the example would be more than welcome.
Would be more than glad to help if you have some spare time to take care of it!
from examples.
I believe the new entry.server file supports React 18 streamining, whereas most of the older examples use React 17 and renderToString
.
I'm not sure how simple, if even possible, it is to update the styled-components
example to the streaming API.
As you can see, styled components first renders the markup as a string, while collecting styles, then injects those styles into the markup. With streaming, the HTML is already being sent to the client while rendering, so nowhere to inject the styles.
examples/styled-components/app/entry.server.tsx
Lines 14 to 21 in 872b8ba
from examples.
Any motion on this? We're wondering the exact same thing.
I guess the fallback is to use React 18 with renderToString
instead?
from examples.
This issue has been automatically closed because we haven't received a response from the original author 🙈. This automation helps keep the issue tracker clean from issues that are unactionable. Please reach out if you have more information for us! 🙂
from examples.
I'm migrating away from styled-components, so I can use a library that supports react 18 streaming rendering 🤷♂️
from examples.
@freshollie We would love to get the styled-components
example updated to work with React 18
from examples.
The example that @freshollie gave works, but why did he receive a thumbs down? Is there something wrong?
from examples.
Related Issues (20)
- Using template as specified does not seem to work HOT 4
- Infinite scrolling example seems to be broken in codesandbox
- Emotion example is outdated HOT 2
- Cookie but missing user in db, ends up being a promise and not redirecting to login HOT 2
- [Feature Request] Framework user wants to have an example integration with Cloudscape Design System HOT 1
- _official-realtime-app Concurrent connections HOT 1
- tailwind styles are not processed in v1.19.2 but are in v1.19.1 HOT 1
- chakra-ui example has hydration issues HOT 2
- Stitches example: Greedy regexp pattern potentially breaks markup HOT 1
- MSW example not working HOT 1
- mdx-bundler example
- Example for Vite + Styled Components?? HOT 1
- Vite + Styled Components Example HOT 4
- Create an example of an app with nested routes
- nprogress uses useTransition, should it use useNavigation instead? HOT 2
- Feature: Pocketbase Auth Example with Realtime Data
- Stripe HOT 1
- sharing-loader-data example choice justification
- Transforming the `socket` example using `vite`
- [framer-route-animation] window should not scroll to top immediately
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from examples.