fix(ssr): imported svg paths set wrong #11012
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
follow up to #10982 which fixes things for svgs too
Problem
As in #10982, importing svg files like
import pathToSVG from "foobar.svg"
fails when SSRing, with webpack setting the path to a localfile://
path, this is due to a misconfiguration in our SSR webpack config.Solution
Mirror the svg config from our client webpack config, with some tweaks to ensure the output path is correct, and the svg doesn't actually get output (the client webpack run takes care of that).
Longer term we should replace
file-loader
with asset modules, but this'll require a change to how we import svgs as react modules, so deferring that for now to the wider webpack cleanup I'm working on.Screenshots
No change
How did you test this change?
Before checking out this change, import an svg somewhere and add it to an
<img>
, let's sayclient/src/homepage/index.tsx
:Run
yarn dev
Open http://localhost:5042/en-US/ and observe an error in the console, along with a broken image:
Security Error: Content at http://localhost:5042/en-US/ may not load or link to file:///workspace/yari/ssr/dist//distimages/0190b323502da5d19d9a1b6ced997386.svg.
Check out this change (keeping the changes to
client/src/homepage/index.tsx
)Run
yarn dev
againOpen http://localhost:5042/en-US/ and observe no error in the console, along with a loaded image!