-
Notifications
You must be signed in to change notification settings - Fork 21
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
Update Electron to latest version 33.3.1 #782
base: trunk
Are you sure you want to change the base?
Conversation
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.
The change looks clear, and the Studio still works fine. I've checked dev build, too, and it installs and runs correctly.
We may upgrade electron-forge
at some point, too, but we will need to review issues with version format change we spotted last time we tried.
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.
Actually, it seems I can't import Jetpack backup to a Studio site anymore as I'm getting the error:
Error occurred in handler for 'importSite': TypeError: Cannot read properties of undefined (reading 'endsWith')
at /Users/cyphelf/Sites/studio/.webpack/main/index.js:227050:58
at Array.some (<anonymous>)
at BackupHandlerFactory.isTarGz (/Users/cyphelf/Sites/studio/.webpack/main/index.js:227050:34)
at BackupHandlerFactory.create (/Users/cyphelf/Sites/studio/.webpack/main/index.js:227034:23)
at /Users/cyphelf/Sites/studio/.webpack/main/index.js:227583:81
at Generator.next (<anonymous>)
at fulfilled (/Users/cyphelf/Sites/studio/.webpack/main/index.js:227546:58)
Thank you, fixed
I can take a look at it. Do we have discussion somewhere to read and get familiar with background and previous attempts. |
Thanks, I will run through the whole smoke test suite.
Sounds great! See #201 for the context and feel free to open a separate issue for that. |
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.
I don't have any decisive feedback on this yet. I'll take another look tomorrow, but @wojtekn might beat me to approving it.
Should we hold off with merging this until the 1.3.2 release to have some more time to test it..?
withMainWindow( ( window ) => { | ||
window.webContents.send( 'test-render-failure' ); | ||
} ); |
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.
Out of curiosity, which change in Electron made it so we had to make this change?
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.
They replaced BrowserWindow with BaseWindow, so in this argument we don't have access to webContents anymore.
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.
src/hooks/use-import-export.tsx
Outdated
@@ -101,9 +101,16 @@ export const ImportExportProvider = ( { children }: { children: React.ReactNode | |||
try { | |||
await stopServer( selectedSite.id ); | |||
|
|||
let filePath: string; | |||
if ( file instanceof File ) { | |||
filePath = getIpcApi().showFilePath( file ); |
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.
The Electron docs led me to believe that we can access webUtils.getPathForFile
directly in this file, but that's clearly not the case when I test it…
How should we understand it when the Electron docs say Process: Renderer
..? cc @Automattic/yolo
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.
I think it's mistake in documentation. After a few days of working with Electron documentation and Issues I noticed that it's not rare case of mistakes in docs.
It should not be in Renderer for sure, since the intention of webUtils.getPathForFile is to move retrieving path logic from Renderer to Preload layer.
@@ -64,7 +64,7 @@ export const ImportExportProvider = ( { children }: { children: React.ReactNode | |||
|
|||
const importFile = useCallback( | |||
async ( | |||
file: BackupArchiveInfo, | |||
file: File | BackupArchiveInfo, |
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.
Why did this work previously? 🤔 Because File
and BackupArchiveInfo
both have a path
prop?
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.
Long story short - If it walks like a duck and quacks like a duck, then it probably is a duck 😂
Will try to explain step by step, maybe it will be easier to understand:
BackupArchiveInfo
isname
andpath
properties- Inside of
importFile
we also expect onlyname
andpath
- So TS doesn't care which extra properties of the object we provide and what the object actualy is. Since anyway we use only these two properties.
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.
I just mean that we clearly passed a File
instance to importFile
previously, too (see below). It's curious that TS didn't bark at us for doing that 🤔
studio/src/hooks/use-add-site.ts
Lines 61 to 64 in 51a4aa2
await importFile( fileForImport, newSite, { | |
showImportNotification: false, | |
isNewSite: 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.
I see what you mean.
Yeah, as I mentioned before, it's about "duck typing".
File is just set of properties, so as soon as we provide all expected properties - it's enough for TS to be happy 😄
If you curious, I made a quick example for you to play with it.
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.
Gotcha 👍 Thanks for the clarification!
I think we should run the whole smoke test suite on Mac and Windows before we merge. |
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.
I didn't encounter any issues while testing the following stuff:
- creating a new blank site
- creating a new site from a Studio export
- creating a new site from a Playground export
- importing a Studio export to an existing site
- importing a database into an existing site
- creating a demo site
- pulling a site
- pushing a site
- chatting with Assistant
- changing the PHP version
- deleting a site
I left a few remarks on the code, but still approving the PR based on my smoke testing on Mac.
Per @wojtekn's latest comment, we should also run a similar test suite on Windows before merging.
src/ipc-types.d.ts
Outdated
* webUtils.getPathForFile is available only inside preload script, that's why this one function is exception and need to be defined here manually. | ||
* | ||
* The nonstandard `path` property of the Web `File` object was added in an early version of Electron as a convenience method for working with native files when doing everything in the renderer was more common. | ||
* However, it represents a deviation from the standard and poses a minor security risk as well, so beginning in Electron 32.0 it has been removed in favor of the [`webUtils.getPathForFile`](api/web-utils.md#webutilsgetpathforfilefile) method. |
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.
* webUtils.getPathForFile is available only inside preload script, that's why this one function is exception and need to be defined here manually. | |
* | |
* The nonstandard `path` property of the Web `File` object was added in an early version of Electron as a convenience method for working with native files when doing everything in the renderer was more common. | |
* However, it represents a deviation from the standard and poses a minor security risk as well, so beginning in Electron 32.0 it has been removed in favor of the [`webUtils.getPathForFile`](api/web-utils.md#webutilsgetpathforfilefile) method. | |
* `webUtils.getPathForFile` is available only inside preload script, that's why this one | |
* function is exception and need to be defined here manually. | |
* | |
* See https://www.electronjs.org/docs/latest/breaking-changes#planned-breaking-api-changes-320 | |
* for more details. |
Nit, but I would shorten this and refer directly to the Electron docs.
src/hooks/use-import-export.tsx
Outdated
let filePath: string; | ||
if ( file instanceof File ) { | ||
filePath = getIpcApi().showFilePath( file ); | ||
} else { |
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.
Maybe we should move this logic to src/hooks/use-add-site.ts
instead? Seems reasonable that this function would consume a single format, and src/hooks/use-add-site.ts
already calls the IPC API in some other places, so it wouldn't be exotic to also introduce a getIpcApi().showFilePath
call
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.
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.
I think src/hooks/use-add-site.ts
is the only place where we pass a File
instance, though.
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.
I double-checked - it's 2 files, not 3. Also content-tab-import-export
src/preload.ts
Outdated
@@ -101,6 +101,7 @@ const api: IpcApi = { | |||
ipcRenderer.invoke( 'getConnectedWpcomSites', localSiteId ), | |||
addSyncOperation: ( id: string ) => ipcRenderer.invoke( 'addSyncOperation', id ), | |||
clearSyncOperation: ( id: string ) => ipcRenderer.invoke( 'clearSyncOperation', id ), | |||
showFilePath: webUtils.getPathForFile, |
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.
showFilePath: webUtils.getPathForFile, | |
getPathForFile: webUtils.getPathForFile, |
I don't think showFilePath
is an ideal name. Something with "get" would be better, since the function is responsible for retrieving a string
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.
I was thinking about it too, but decided to take this name, since it was somewhere in documentation, don't remember where exactly I saw it. It's hard to provide some arguments or explain my thoughts, but I will try 😅
This name is provided by creators of Electron, so maybe it will be kinda-ish following style guides for naming
. I just want to believe, that they were thinking about something, when gave this name to "expose it to main world".
Totally not strong arguments, it's more about my feelings 😅 So I am ok to go with either name, just decided to explain my decision 🙂
Also, if we decided to use something else instead of showFilePath
- I think it's better to chose whatever, but not getPathForFile
, to simplify Command + F
across our codebase, avoid confusion and simplify reading code at a glance.
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.
if we decided to use something else instead of showFilePath - I think it's better to chose whatever, but not getPathForFile , to simplify Command + F across our codebase, avoid confusion and simplify reading code at a glance
I actually think that reusing the getPathForFile
name makes sense since we are simply exposing that API without any modifications.
* chore(package.json): update electron-forge to latest version 7.6.1 * chore: space * chore: test removing overrides for electron-packager * chore: revert testing broken Windows
src/hooks/use-import-export.tsx
Outdated
let filePath: string; | ||
if ( file instanceof File ) { | ||
filePath = getIpcApi().getPathForFile( file ); | ||
} else { | ||
filePath = file.path; | ||
} |
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.
let filePath: string; | |
if ( file instanceof File ) { | |
filePath = getIpcApi().getPathForFile( file ); | |
} else { | |
filePath = file.path; | |
} | |
const filePath = file instanceof File ? getIpcApi().getPathForFile( file ) : file.path; |
We could make this slightly more compact
Related issues
Proposed Changes
With this PR we are updating Electron to the latest version to keep it up-to-date.
Testing Instructions
npm start
Electron
in the app's menu and thenTest Render Failure (dev only)