-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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: add missing fs method rewrites to handle fetchRemoteFile in dsg/ssr engine #38822
Conversation
@@ -29,7 +29,7 @@ const configs = [ | |||
{ | |||
title: `remote-file (SSR, Page Query)`, | |||
pagePath: `/routes/ssr/remote-file/`, | |||
placeholders: false, | |||
placeholders: true, |
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 test was disabled because of problems that this PR is fixing. In context of this test those problems weren't fatal, however it meant that image placeholders were just not working.
The fix in this PR also solves other problems than just placeholders, but this was existing test that already we had
1d97c5a
to
b6d9442
Compare
@@ -1,4 +1,4 @@ | |||
import crypto from "crypto" | |||
import { createHash } from "crypto" |
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 caused some problems with
Cannot find module '@babel/runtime/helpers/interopRequireDefault'
in lambdas, so easiest way was just to avoid having babel adding that
private setupPathPrefix(pathPrefix: string): void { | ||
if (pathPrefix) { | ||
store.dispatch({ | ||
type: `SET_PROGRAM`, | ||
payload: { | ||
prefixPaths: true, | ||
}, | ||
}) | ||
|
||
store.dispatch({ | ||
type: `SET_SITE_CONFIG`, | ||
payload: { | ||
...store.getState().config, | ||
pathPrefix, | ||
}, | ||
}) | ||
} | ||
} | ||
|
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.
needed for pathPrefix to be actually honored when generating FILE_CDN urls
export function getServerData() { | ||
return { | ||
props: { | ||
ssr: true, | ||
}, | ||
} | ||
} |
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 page wasn't actually SSR... Making it SSR uncovered some other problems that this PR is also fixing
903659a
to
c08ed55
Compare
// @ts-ignore TS doesn't like extending prototype "classes" | ||
lfs.ReadStream = LinkedReadStream | ||
|
||
const dbPath = path.join(TEMP_CACHE_DIR, `data`, `datastore`) | ||
|
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.
Seems like there's some repetition here with extending fs.WriteStream and fs.ReadStream, you could consider extracting/reusing.
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.
Yes, it's basically the same thing twice (just once for WriteStream
and once for ReadStream
- I think it's confusing as it is already and trying to create reusable utility would probably make debugging / understanding it worse than it already is.
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.
Doing class ... extends
would be much more readable, but you can't actually do that is "class" you extend is prototype one like fs.WriteStream
and fs.ReadStream
are ( https://github.com/nodejs/node/blob/6b6bcee747c2007117262efb2ff6d61ea888f499/lib/internal/fs/streams.js#L321-L398 being one of them - the other is also in that module)
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.
Got it, I'm ok leaving as is.
…ssr engine (#38822) * test(adapters-e2e): enable placeholder tests in ssr remote-file * fix(gatsby-adapter-netlify): bundling file-cdn * fix(gatsby): set pathPrefix in engines * fix(gatsby): add missing fs method rewrites to handle fetchRemoteFile in dsg/ssr engine (cherry picked from commit bbdddd7)
…ssr engine (#38822) (#38823) * test(adapters-e2e): enable placeholder tests in ssr remote-file * fix(gatsby-adapter-netlify): bundling file-cdn * fix(gatsby): set pathPrefix in engines * fix(gatsby): add missing fs method rewrites to handle fetchRemoteFile in dsg/ssr engine (cherry picked from commit bbdddd7) Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
Description
This PR fixes issues when
fs.createWriteStream
(and few others) are being used in functions/lambdas that are mounted in read-only locationsExample error could look like this:
But any issue (there might be multiple context in which this issue occurs) that looks more or less like this:
is caused by same root issue which is fact that linked FS (that rewrites path from read-only location to writeable location) didn't cover required FS methods.
This PR adds rewrite handling for:
fs.createWriteStream
fs.createReadStream
fs.rm
new fs.WriteStream
new fs.ReadStream
And add rewrite support for second (
to
) argument for ( currently only first (from
) argument is being rewritten)fs.rename
fs.renameSync
This PR also handles few issues that were discovered during work on missing FS rewrites:
Tests
Fixed adapter e2e test fixture to actually use SSR for SSR Remote File tests. Enabled placeholder tests for SSR Remote File page (placeholder generation did not work due to missing FS rewrites)
Related Issues
https://linear.app/netlify/issue/FRA-236/fatal-createwritestream-problem-with-linkfs