-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Next.js' static
assetPrefix
with __webpack_public_path__
…
…to support dynamic path prefix (#16967) ## Summary & Motivation This pr addresses a performance issue reported by a user: https://dagster.slack.com/archives/C01U954MEER/p1695936650103649 This is an alternative approach to #16941 that avoids needing to string replace javascript files at run time and instead replaces at buildtime using `__webpack_public_path__`. This solution is pretty hacky for webworkers and may need tweaking in the future if we start SSRing more of the app. For workers we grab the path from the global location object. ## How I Tested These Changes Built the app and ran `dagster-webserver -p 4444 --path-prefix=/test1235` and made sure the app still worked including webworkers. This doesn't affect cloud or local development (I tested local development and it just ignores __webpack_public_path__).
- Loading branch information
Showing
4 changed files
with
43 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
js_modules/dagster-ui/packages/app-oss/replace-asset-prefix.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function replaceStringInFile(filePath, searchString, replacement) { | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
const replacedContent = fileContent.replace(new RegExp(searchString, 'g'), replacement); | ||
fs.writeFileSync(filePath, replacedContent); | ||
} | ||
|
||
function processDirectory(directory) { | ||
const files = fs.readdirSync(directory); | ||
|
||
for (const file of files) { | ||
const filePath = path.join(directory, file); | ||
|
||
const isDirectory = fs.statSync(filePath).isDirectory(); | ||
|
||
if (isDirectory) { | ||
// Recursively process subdirectories | ||
processDirectory(filePath); | ||
} else if (file.endsWith('.js')) { | ||
replaceStringInFile( | ||
filePath, | ||
'"BUILDTIME_ASSETPREFIX_REPLACE_ME', | ||
// if typeof window === "undefined" then we are inside a web worker | ||
// Grab the path from the location object | ||
'(() => {if (typeof window === "undefined") {return self.location.pathname.split("/_next/")[0]} return self.__webpack_public_path__ || "";})() + "', | ||
); | ||
} | ||
} | ||
} | ||
|
||
processDirectory(__dirname + '/build/'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters