WizardBuilder: sidebar categories stop opening/closing after "+ Page" (addPage() rebuilds twice)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
Research direction
Start with src/WizardBuilder.js, especially addPage() and its saveComponent listener, then trace the fallback toggle wiring in src/WebformBuilder.js around attach(). Reproduce in the provided stock builder setup by adding a page and clicking a sidebar category twice. Done when adding or pasting a page leaves each category able to open and close on successive clicks.
Written by the indexing model from the issue text.
Description
Describe the bug
In the wizard builder, after clicking "+ Page" the sidebar categories (Basic, Advanced, Layout, Data, Premium) no longer open or close. A click on a closed category does nothing, and the open one can't be closed. Only reloading the builder brings them back. Copy + paste of a whole page has the same effect, because the paste goes through addPage() too.
It happens when Bootstrap's collapse JavaScript is not loaded (window.bootstrap.Collapse undefined), so the builder falls back to its own toggle handlers. That is the default with the stock formio.full.min.js.
Cause
WizardBuilder.addPage() rebuilds twice:
- It calls
emitSaveComponentEvent(newPage, newPage, ...). WizardBuilder's ownsaveComponentlistener findsnewPageinthis._form.components(it was just pushed there) and callsthis.rebuild(). - Then
addPage()itself ends withreturn this.rebuild();.
src/WizardBuilder.js on main, L58-L80 and L228-L247:
this.on('saveComponent', (component, originalComponent) => {
...
if (this._form.components.includes(originalComponent)) {
this._form.components[this._form.components.indexOf(originalComponent)] = component;
this.rebuild(); // <-- rebuild #1, triggered from addPage
}
...
}, true);
addPage(page) {
...
this._form.components.push(newPage);
this.emitSaveComponentEvent(newPage, newPage, this._form, 'components', this._form.components.length - 1, true, newPage);
this.emit('change', this._form);
return this.rebuild(); // <-- rebuild #2
}
WebformBuilder.attach() wires the fallback toggles inside super.attach(element).then(...) (L632, L657-L707). The two rebuilds overlap, both .then callbacks run after the second render, and both call loadRefs on the same final DOM. So every category button ends up with two click handlers, each calling hideShow(group, false, true). One click toggles the group open and straight back closed.
Probe on the repro page below (a click listener counter on [ref="sidebar-anchor"], Advanced category):
| Action | rebuild() calls |
click listeners on the button |
|---|---|---|
builder.redraw() |
n/a | 1 |
builder.addPage() |
2 | 2 |
Version/Branch
Reproduced on @formio/[email protected] (current latest) and on 5.4.1. The code above is unchanged on main (90732a2).
To Reproduce
Self-contained page, stock formio.full.min.js, default builder options:
<link rel="stylesheet" href="formio.full.min.css">
<script src="formio.full.min.js"></script>
<div id="builder"></div>
<script>
Formio.builder(document.getElementById('builder'), { display: 'wizard', components: [] })
.then(function (b) { window.builder = b; });
</script>
- Click "Advanced" in the sidebar: it opens. Click it again: it closes. (Works.)
- Click "+ Page".
- Click "Advanced": it stays closed. Click "Basic": it stays open. Every category behaves the same way.
- Reload, then copy page 1 and paste it as a new page: same result.
Checked with Playwright on 5.7.0, clicking each category twice:
| Basic | Advanced, Layout, Data, Premium | |
|---|---|---|
| Fresh builder | closes, then opens | open, then close |
| After "+ Page" | stays open | stay closed |
Expected behavior
"+ Page" (and pasting a page) rebuilds the builder once, and every sidebar category still opens and closes on click.
Additional context
Suggested fix: make addPage() rebuild once. For example, let the saveComponent listener skip the rebuild for a page that addPage() itself just pushed, or drop the trailing this.rebuild() and return the listener's rebuild. Making the fallback toggle wiring idempotent (remove the previous sidebar handlers before adding new ones) would also protect against any other overlapping rebuilds.
Workaround for anyone hitting this: wrap the prototype so the rebuilds inside addPage() collapse into one (checked on 5.7.0 for both "+ Page" and page paste):
const proto = Formio.Builders.builders.wizard.prototype;
const original = proto.addPage;
proto.addPage = function (...args) {
const hasOwn = Object.prototype.hasOwnProperty.call(this, 'rebuild');
const ownRebuild = this.rebuild;
this.rebuild = () => Promise.resolve();
try {
original.apply(this, args);
} finally {
if (hasOwn) {
this.rebuild = ownRebuild;
} else {
delete this.rebuild;
}
}
return this.rebuild();
};
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 1.1k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from formio/formio.js
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
SelectBoxes.checkComponentValidity returns false without populating the caller's errors array, so required + minSelectedCount is never enforcedMay be free again @aliassar claimed this 16 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 4/5 3-5 days Newbie friendliness 54/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
All issues in formio/formio.js
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
anothaDev/luci-theme-vantage#143 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kingcharleslzy-ai/dsh-purge#282 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
a-corriger bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
christian-raj/S-Aloha#340 ·
-
area:image documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day