When switching themes switch the figma native theme mode selector if possible#2336
Conversation
…into 2187-when-switching-themes-switch-the-figma-native-theme-mode-selector-if-possible
🦋 Changeset detectedLatest commit: 21f2ae5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR Analysis
PR Feedback
How to use
|
| if ('message' in msg) { | ||
| if (msg.message.type === 'async/get-theme-info') { | ||
| if ('activeTheme' in msg.message && 'themes' in msg.message) { | ||
| const { activeTheme } = msg.message; |
There was a problem hiding this comment.
| const { activeTheme } = msg.message; | |
| const { activeTheme, themes } = msg.message; |
| if (msg.message.type === 'async/get-theme-info') { | ||
| if ('activeTheme' in msg.message && 'themes' in msg.message) { | ||
| const { activeTheme } = msg.message; | ||
| const { themes } = msg.message; |
There was a problem hiding this comment.
| const { themes } = msg.message; | |
| const themeToFind = Object.values(activeTheme)[0]; |
| if ('activeTheme' in msg.message && 'themes' in msg.message) { | ||
| const { activeTheme } = msg.message; | ||
| const { themes } = msg.message; | ||
| const activeMode = themes.filter((theme) => theme.id === Object.values(activeTheme)[0])[0]; |
There was a problem hiding this comment.
| const activeMode = themes.filter((theme) => theme.id === Object.values(activeTheme)[0])[0]; | |
| const activeMode = themes.find((theme) => theme.id === themeToFind); |
|
Can you add a changeset so we can inform the users about this change? Check to see if the fixes for the lookup fix the OOM error, otherwise we'll have to double check why that's occurring |
|
Tests are failing here |
…into 2187-when-switching-themes-switch-the-figma-native-theme-mode-selector-if-possible
…into 2187-when-switching-themes-switch-the-figma-native-theme-mode-selector-if-possible
|
Commit SHA:4c507f93be36defe7933184695662c0f75d72629 Test coverage results 🧪
|
|
Commit SHA:4c507f93be36defe7933184695662c0f75d72629 |
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| const activeMode = themes.find((theme) => theme.id === themeToFind); | ||
| if (figma.currentPage.children && figma.currentPage.children.length > 0) { | ||
| figma.currentPage.children.forEach((frame) => { | ||
| frame.setExplicitVariableModeForCollection(activeMode?.$figmaCollectionId ?? '', activeMode?.$figmaModeId ?? ''); |
There was a problem hiding this comment.
Shouldn't we be using an if around this and checking that the string id's exist? What happens when we these are invalid or null?
There was a problem hiding this comment.
yeah it could be that the information is outdated and then this will error. they'll likely not be invalid or null but it could be that it doesnt exist anymore causing an error.
let's check for if a) those are set and b) wrap so that we dont crash
| this.attachMessageListener((msg: IncomingMessageEvent<AsyncMessageResults & { type: Message['type'] }>['data']['pluginMessage']) => { | ||
| if (msg.id === messageId) { | ||
| if ('message' in msg) { | ||
| if (msg.message.type === 'async/get-theme-info') { |
There was a problem hiding this comment.
i dont think this belongs here. this file doesnt have any of the other message handlers, this needs to go elsewhere where we define those.
this feels like the right place
| const activeMode = themes.find((theme) => theme.id === themeToFind); | ||
| if (figma.currentPage.children && figma.currentPage.children.length > 0) { | ||
| figma.currentPage.children.forEach((frame) => { | ||
| frame.setExplicitVariableModeForCollection(activeMode?.$figmaCollectionId ?? '', activeMode?.$figmaModeId ?? ''); |
There was a problem hiding this comment.
yeah it could be that the information is outdated and then this will error. they'll likely not be invalid or null but it could be that it doesnt exist anymore causing an error.
let's check for if a) those are set and b) wrap so that we dont crash
| const themeToFind = Object.values(activeTheme)[0]; | ||
| const activeMode = themes.find((theme) => theme.id === themeToFind); | ||
| if (figma.currentPage.children && figma.currentPage.children.length > 0) { | ||
| figma.currentPage.children.forEach((frame) => { |
There was a problem hiding this comment.
this ignores the issue requirement completely and sets an active variable mode for every frame on the current page. this is not what we need. we need to apply way more logic here than that.
the issue states that it should have different behavior depending on the apply mode
| if (msg.message.type === 'async/get-theme-info') { | ||
| if ('activeTheme' in msg.message && 'themes' in msg.message) { | ||
| const { activeTheme, themes } = msg.message; | ||
| const themeToFind = Object.values(activeTheme)[0]; |
There was a problem hiding this comment.
we do not just want to switch the first theme, but all theme groups that are active
20231025_133845.mp4
Closes #2187