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(create-gatsby): Remove race condition/duplicate render #28484

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions packages/create-gatsby/src/components/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,33 @@ export class SelectInput extends Select {
return undefined
}

let styles = this.styles
let focused = this.index === i
let style = focused ? styles.primary : val => val
let ele = await this.resolve(val[focused ? `on` : `off`] || val, this.state)
const styles = this.styles
const focused = this.index === i
const style = focused ? styles.primary : val => val
const ele = await this.resolve(
val[focused ? `on` : `off`] || val,
this.state
)
return focused ? style(ele) : ` `.repeat(ele.length)
}

async render() {
let { submitted, size } = this.state
const { submitted, size } = this.state

let prompt = ``
let header = await this.header()
let prefix = await this.prefix()
let message = await this.message()
const header = await this.header()
const prefix = await this.prefix()
const message = await this.message()

if (this.options.promptLine !== false) {
prompt = [prefix, message].join(` `)
this.state.prompt = prompt
}

let output = await this.format()
let help = (await this.error()) || (await this.hint())
let body = await this.renderChoices()
let footer = await this.footer()
const output = await this.format()
const help = (await this.error()) || (await this.hint())
const body = await this.renderChoices()
const footer = await this.footer()

if (output) prompt += `\n` + output
if (help && !prompt.includes(help)) prompt += `\n` + help
Expand Down Expand Up @@ -83,11 +86,7 @@ export class MultiSelectInput extends SelectInput {
}

toggle(choice, enabled) {
if (choice.name === `___done`) {
super.submit()
} else {
super.toggle(choice, enabled)
}
super.toggle(choice, enabled)
}

async toChoices(value, parent) {
Expand All @@ -112,6 +111,9 @@ export class MultiSelectInput extends SelectInput {
}

submit() {
if (this.focused.name === `___done`) {
return super.submit()
}
return this.space()
}

Expand Down