-
Notifications
You must be signed in to change notification settings - Fork 973
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
Feature/prerender image support #1721
Conversation
Converting back to draft, I will rebase the relevant code after merge of #1641 |
76ba73a
to
c1b4cf8
Compare
c1b4cf8
to
425a25a
Compare
@peterp ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, just a few changes to the package.json files.
I'm a little concerned about the having to wrap the SVG imports into functions, since that would introduce a breaking change? As an example:
import MyIcon from './MyIcon.svg'
export const MyComponent = () => {
<div>
<MyIcon />
</div>
}
Would this not work anymore? It's odd to me, since the documentation seems to indicate that it creates a component.
If this is the case then this is a huge breaking change.
@dac09 I took this for a spin locally. (Note: I'm having a lot of trouble these days with my local dev setup. PR Packages don't seem to be created correctly, i.e. the inter-dependencies aren't actually to the PR package versions. Verdaccio was failing. And Got this code to prerender: // .../BlogLayout.js
...
import FaviconImage from './favicon.png'
const Favicon = () => <FaviconImage />
const BlogLayout = ({ children }) => {
const { logIn, logOut, isAuthenticated, currentUser } = useAuth()
return (
<>
<header>
<h1>
<img src={Favicon} /> <Link to={routes.home()}>Redwood Blog</Link>
</h1>
... Ran But when I ran Could not resolve "/Users/price/Repos/tdp-tutorial-blog-test/web/src/pages/FatalErrorPage" in file /Users/price/Repos/tdp-tutorial-blog-test/web/src/index.js.
Could not resolve "/Users/price/Repos/tdp-tutorial-blog-test/web/src/layouts/BlogLayout" in file /Users/price/Repos/tdp-tutorial-blog-test/web/src/pages/AboutPage/AboutPage.js.
Warning: Invalid value for prop `src` on <img> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM. For details, see https://fb.me/react-attribute-behavior
...
::: Dry run, not writing changes :::
::: 🚀 Prerender output for /about :::
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="icon" type="image/png" href="/favicon.png" />
<title>tdp-tutorial-blog-test</title>
<script defer="defer" src="/static/js/runtime-app.31ca6fe6.js"></script>
<script defer="defer" src="/static/js/vendors.9e95d691.chunk.js"></script>
<script defer="defer" src="/static/js/app.87f08f92.chunk.js"></script>
<link href="/static/css/app.6d4df765.css" rel="stylesheet" />
</head>
<body>
<div id="redwood-app">
<header>
<h1><img /> <a href="/">Redwood Blog</a></h1>
... |
@peterp that would definitely work. It's only when you are "re-exporting" an image that it doesn't work. |
…dwood into feature/prerender-image-support * 'feature/prerender-image-support' of github.com:dac09/redwood: Update yarn.lock use 'prisma' in place of '@prisma/cli' (redwoodjs#1800)
There's a syntax error there, the way imported images work (unless they're svg) is: import FaviconImage from './favicon.png'
return (
<>
<header>
<h1>
<img src={FaviconImage} /> <Link to={routes.home()}>Redwood Blog</Link>
</h1>
... So you can skip that extra |
Ah, got it. OK, gonna need more. Doc. POWER 🦾⚡️ |
I think its documented somewhere, definitely seen it before. Defo worth exposing a bit more though its maintaining the behaviour from before, not introducing something new! |
…rib-workspaces * 'main' of github.com:redwoodjs/redwood: Lint the create-redwood-app template. (redwoodjs#1822) Update typescript lint rule for no-unused-vars (redwoodjs#1808) Router: Fix TS types (redwoodjs#1823) Generate globals for routes (redwoodjs#1744) Ethereum auth update to v0.2.1 (redwoodjs#1807) Better messages when no routes marked with prerender (redwoodjs#1821) Feature/prerender image support (redwoodjs#1721) Fix entry js | Make index a little more readable, as it confuses people (redwoodjs#1819) use 'prisma' in place of '@prisma/cli' (redwoodjs#1800)
* chore(deps): remove svg-react-loader svg-react-loader doesn't appear to be used as of d57003a (Feature/prerender image support (#1721), 2021-02-19) and depends on a vulnerable version of loader-utils (see CVE-2022-37601) * chore: update yarn.lock
* chore(deps): remove svg-react-loader svg-react-loader doesn't appear to be used as of d57003a (Feature/prerender image support (#1721), 2021-02-19) and depends on a vulnerable version of loader-utils (see CVE-2022-37601) * chore: update yarn.lock
* chore(deps): remove svg-react-loader svg-react-loader doesn't appear to be used as of d57003a (Feature/prerender image support (#1721), 2021-02-19) and depends on a vulnerable version of loader-utils (see CVE-2022-37601) * chore: update yarn.lock
Builds on top of #1641
What?
When rendering in the Node.js environment, babel doesn't know how to handle images.
This PR does the following things:
Why?
So that we can prerender pages where media is imported like
Other notes
1. I've noticed there are subtle differences in how SVGs are handled. For example, this won't work anymore:
Logo.js
but this will