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

fix(ssr): imported svg paths set wrong #11012

Merged
merged 1 commit into from
May 2, 2024
Merged

Conversation

LeoMcA
Copy link
Member

@LeoMcA LeoMcA commented Apr 26, 2024

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 local file:// 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 say client/src/homepage/index.tsx:

...
import example from "../assets/mdn-logo.svg";
...
<img src={example} />
...

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 again
Open http://localhost:5042/en-US/ and observe no error in the console, along with a loaded image!

follow up to #10982 which fixes things for svgs too
@LeoMcA LeoMcA requested a review from a team as a code owner April 26, 2024 13:25
@caugner caugner merged commit ec1ded9 into main May 2, 2024
12 checks passed
@caugner caugner deleted the fix-webpack-ssr-svg-url branch May 2, 2024 22:05
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.

2 participants