Skip to content

Commit

Permalink
luci-base: force menu to regenerate after uci change
Browse files Browse the repository at this point in the history
Because the menu JSON can have 'depends' in them, uci changes
should force the menu to regenerate.

Closes #6423

Signed-off-by: James Haggerty <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
  • Loading branch information
wryun authored and systemcrash committed Mar 16, 2024
1 parent 6abb5ed commit 97ebdcb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions modules/luci-base/htdocs/luci-static/resources/uci.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ return baseclass.extend(/** @lends LuCI.uci.prototype */ {
window.setTimeout(try_confirm, 250);
else
return Promise.reject(rv);
} else {
document.dispatchEvent(new CustomEvent('uci-applied'));
}

return rv;
Expand Down
4 changes: 4 additions & 0 deletions modules/luci-base/htdocs/luci-static/resources/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3478,6 +3478,10 @@ var UITable = baseclass.extend(/** @lends LuCI.ui.table.prototype */ {
}
});

// Because the menu can depend on uci values, we need to flush the cache
// after uci mutations.
document.addEventListener('uci-applied', () => UIMenu.flushCache());

/**
* @class ui
* @memberof LuCI
Expand Down
2 changes: 1 addition & 1 deletion modules/luci-base/ucode/dispatcher.uc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function build_pagetree() {
firstchild_ineligible: 'bool'
};

let files = glob('/usr/share/luci/menu.d/*.json', '/usr/lib/lua/luci/controller/*.lua', '/usr/lib/lua/luci/controller/*/*.lua');
let files = glob('/usr/share/luci/menu.d/*.json', '/etc/config/*', '/usr/lib/lua/luci/controller/*.lua', '/usr/lib/lua/luci/controller/*/*.lua');
let cachefile;

if (indexcache) {
Expand Down

16 comments on commit 97ebdcb

@schm0
Copy link

@schm0 schm0 commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This results in:

/usr/lib/lua/luci/ucodebridge.lua:23: /usr/lib/lua/luci/dispatcher.lua:102: module 'luci.controller.' not found:
no field package.preload['luci.controller.']
no file './luci/controller/.lua'
no file '/usr/share/lua/luci/controller/.lua'
no file '/usr/share/lua/luci/controller//init.lua'
no file '/usr/lib/lua/luci/controller/.lua'
no file '/usr/lib/lua/luci/controller//init.lua'
no file './luci/controller/.so'
no file '/usr/lib/lua/luci/controller/.so'
no file '/usr/lib/lua/loadall.so'
no file './luci.so'
no file '/usr/lib/lua/luci.so'
no file '/usr/lib/lua/loadall.so'

In error(), file [C]
called from function [anonymous function] (/usr/lib/lua/luci/ucodebridge.lua:23)
called from function ((tail call))
In [anonymous function](), file /usr/share/ucode/luci/runtime.uc, line 148, byte 45:
  called from function build_pagetree (/usr/share/ucode/luci/dispatcher.uc:382:73)
  called from function menu_json (/usr/share/ucode/luci/dispatcher.uc:439:26)
  called from function [anonymous function] (/usr/share/ucode/luci/dispatcher.uc:898:24)
  called from anonymous function (/www/cgi-bin/luci:39:13)

 `        return lcall.call(modname, method, ...args);`
  Near here ----------------------------------------^

@systemcrash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you running a lua based app?
What were your actions leading up to this error?

@xh0823
Copy link

@xh0823 xh0823 commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime error
Unhandled exception during request dispatching
/usr/lib/lua/luci/ucodebridge.lua:23: /usr/lib/lua/luci/dispatcher.lua:102: module 'luci.controller.' not found:
no field package.preload['luci.controller.']
no file './luci/controller/.lua'
no file '/usr/share/lua/luci/controller/.lua'
no file '/usr/share/lua/luci/controller//init.lua'
no file '/usr/lib/lua/luci/controller/.lua'
no file '/usr/lib/lua/luci/controller//init.lua'
no file './luci/controller/.so'
no file '/usr/lib/lua/luci/controller/.so'
no file '/usr/lib/lua/loadall.so'
no file './luci.so'
no file '/usr/lib/lua/luci.so'
no file '/usr/lib/lua/loadall.so'

In error(), file [C]
called from function [anonymous function] (/usr/lib/lua/luci/ucodebridge.lua:23)
called from function ((tail call))
In anonymous function, file /usr/share/ucode/luci/runtime.uc, line 148, byte 45:
called from function build_pagetree (/usr/share/ucode/luci/dispatcher.uc:382:73)
called from function menu_json (/usr/share/ucode/luci/dispatcher.uc:439:26)
called from function [anonymous function] (/usr/share/ucode/luci/dispatcher.uc:898:24)
called from anonymous function (/www/cgi-bin/luci:39:13)

return lcall.call(modname, method, ...args);
Near here ----------------------------------------^

@zxlhhyccc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xh0823 Will a rollback solve the problem? I haven't used it yet!

@xh0823
Copy link

@xh0823 xh0823 commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xh0823 Will a rollback solve the problem? I haven't used it yet!

You try it, I'm a little bit busy

@schm0
Copy link

@schm0 schm0 commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@systemcrash

Just trying to access the routers web interface.
It doesn't even reach the login page.

@zxlhhyccc
Yes, resolving it solves it.

@zxlhhyccc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schm0 How did you solve it? Did the rollback solve it?

@schm0
Copy link

@schm0 schm0 commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the rollback solve it?

yes

@zxlhhyccc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

97ebdcb#diff-ba767cec24091f883573c9364ef8ff2efaaabfb050a9c2f485adc9a3bf17a9d0R361
Rollback can be, why add /etc/config/* can not understand!

@hnyman
Copy link
Contributor

@hnyman hnyman commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the error right after I flashed a new version for E8450/RT3200 and the router rebooted. The error comes already before the login screen.

Removing the /etc/config/* addition from dispatcher.uc fixed things, and LuCI can again be accessed.
But that removes the core idea of this change, I think.

I will revert this until @systemcrash figures a fix.

@systemcrash
Did this actually work for you? Did you test this?
I wonder what is the difference in your LuCI.

@hnyman
Copy link
Contributor

@hnyman hnyman commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in f2a4910

@systemcrash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it, but evidently needed to reboot to hit that part. I also reverted it but forgot to push 🙈

Thanks @hnyman

@jow-
Copy link
Contributor

@jow- jow- commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I NACKed this previously and now you pushed it anyway and broke master (once again) in the process.

@systemcrash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously? #6423 ? Or some other avenue?

@systemcrash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, yes. It's verified that exactly these changes cause problems.

@dannil
Copy link
Contributor

@dannil dannil commented on 97ebdcb Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried checking out this commit and applying the changes and it crashed immediately for me on a Ctrl+F5, no reboot necessary. I'm running with ccache disabled on my dev machine if that would make a difference.

Please sign in to comment.