inertia-sails 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/render.js +10 -1
  2. package/package.json +1 -1
package/lib/render.js CHANGED
@@ -32,6 +32,15 @@ module.exports = async function render(req, res, data) {
32
32
  return res.json(page)
33
33
  } else {
34
34
  // Implements full page reload
35
- return res.view(rootView, { page, ...allLocals })
35
+ //
36
+ // We pass locals both as top-level properties AND nested under a `locals`
37
+ // key. This is necessary because Sails's default EJS renderer creates an
38
+ // `options.locals` object (for blocks, layout, partial helpers). EJS wraps
39
+ // templates in `with(data) { ... }`, so inside the template `locals`
40
+ // resolves to `data.locals` (the nested object) rather than the `locals`
41
+ // function parameter. By pre-populating `data.locals` with our values,
42
+ // `<%= locals.title %>` in the EJS template correctly resolves to the
43
+ // dynamic value instead of undefined.
44
+ return res.view(rootView, { page, ...allLocals, locals: { ...allLocals } })
36
45
  }
37
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-sails",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "The Sails adapter for Inertia.",
5
5
  "main": "index.js",
6
6
  "sails": {