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

perf: performance overhaul #26114

Open
wants to merge 397 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 172 commits
Commits
Show all changes
397 commits
Select commit Hold shift + click to select a range
60cad85
perf: more templates.ts
GalacticHypernova Mar 20, 2024
4e3a05d
Merge branch 'main' into patch-9
GalacticHypernova Mar 20, 2024
50f4e49
perf: more templates.ts
GalacticHypernova Mar 20, 2024
d332da9
fix: use variable
GalacticHypernova Mar 20, 2024
d4d3ff3
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 20, 2024
a6447a1
chore: partial revert templates.ts
GalacticHypernova Mar 20, 2024
6bd68c4
chore: return
GalacticHypernova Mar 20, 2024
efb6f39
chore: end \n
GalacticHypernova Mar 20, 2024
0b0a31d
perf: components.ts
GalacticHypernova Mar 20, 2024
4049ba4
perf: module.ts
GalacticHypernova Mar 20, 2024
c8cf648
perf: transform.ts
GalacticHypernova Mar 20, 2024
014a4d7
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 20, 2024
669e827
Merge branch 'main' into patch-9
GalacticHypernova Mar 20, 2024
aafb057
revert: transform.ts
GalacticHypernova Mar 20, 2024
7a8b1dc
Merge branch 'main' into patch-9
GalacticHypernova Mar 24, 2024
29ee79e
fix: appending `
GalacticHypernova Mar 24, 2024
d547053
[autofix.ci] apply automated fixes
autofix-ci[bot] Mar 24, 2024
826f6b4
perf: client.ts
GalacticHypernova Mar 24, 2024
6a2d314
Merge branch 'main' into patch-9
GalacticHypernova May 14, 2024
14bca76
fix: remove unnecessary parenthesis
GalacticHypernova May 14, 2024
27cca0a
fix: remove unnecessary parenthesis
GalacticHypernova May 14, 2024
dfeccc4
fix: add correct type to content
GalacticHypernova May 14, 2024
0b422a4
fix: use genImport
GalacticHypernova May 14, 2024
6dd29f3
Merge branch 'main' into patch-9
GalacticHypernova May 18, 2024
bb913e8
chore: extract stringified values to variables for redundancy
GalacticHypernova May 18, 2024
913e874
chore: revert component.ts for later reiteration
GalacticHypernova May 18, 2024
44995ce
chore: partially revert templates
GalacticHypernova May 18, 2024
619433b
perf: use array for slotVNodes textContent operations
GalacticHypernova May 18, 2024
c04a4a3
chore: partially revert component transform
GalacticHypernova May 18, 2024
42dd636
chore: attempting without explicit typing
GalacticHypernova May 18, 2024
ec990be
fix: export appId
GalacticHypernova May 18, 2024
c159775
chore: partially revert nitro.ts
GalacticHypernova May 18, 2024
2d43487
[autofix.ci] apply automated fixes
autofix-ci[bot] May 18, 2024
b1e3771
Merge branch 'main' into patch-9
GalacticHypernova Jun 2, 2024
25d3260
chore: remove unnecessary double newline
GalacticHypernova Jun 2, 2024
aee1352
fix(nuxt-error-page): join stacktrace outside the if
GalacticHypernova Jun 2, 2024
b3779c4
perf: module.ts
GalacticHypernova Jun 2, 2024
5d5c42e
fix: add single quotes
GalacticHypernova Jun 2, 2024
49811cd
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 2, 2024
01b04ee
perf: simplify route middleware path
GalacticHypernova Jun 2, 2024
37bd974
perf: public-dirs.ts
GalacticHypernova Jun 2, 2024
b751473
perf: avoid a second dirname call
GalacticHypernova Jun 2, 2024
a15e512
perf: template.ts
GalacticHypernova Jun 2, 2024
25e2e15
fix: missing parenthesis
GalacticHypernova Jun 2, 2024
bd980df
chore: remove extra parentheses
GalacticHypernova Jun 2, 2024
1f37837
perf: more nitro.ts
GalacticHypernova Jun 2, 2024
978c152
perf: simplify if check
GalacticHypernova Jun 2, 2024
b9211cb
perf: style.ts
GalacticHypernova Jun 2, 2024
e934ae4
perf: manifest.ts
GalacticHypernova Jun 2, 2024
2b65642
perf: server.ts
GalacticHypernova Jun 2, 2024
853b32e
ercss.ts
GalacticHypernova Jun 2, 2024
9c36c87
chore: return newline
GalacticHypernova Jun 2, 2024
7df1a94
fix: comma
GalacticHypernova Jun 2, 2024
7b65f15
fix: use diff name
GalacticHypernova Jun 2, 2024
38c33a0
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 2, 2024
e68ecf5
perf: more renderer.ts
GalacticHypernova Jun 2, 2024
b263991
fix: ensure sharedCache is non-null
GalacticHypernova Jun 2, 2024
0bdb701
perf: state.ts
GalacticHypernova Jun 3, 2024
513bd3a
perf: composables.ts
GalacticHypernova Jun 3, 2024
5ced306
perf: more component improvements with flatMap
GalacticHypernova Jun 3, 2024
16787dd
perf: ssr-styles.ts
GalacticHypernova Jun 3, 2024
7c9afa4
fix: closing parenthesis
GalacticHypernova Jun 3, 2024
b305635
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 3, 2024
3ed3b94
perf: more islandsTransform.ts
GalacticHypernova Jun 3, 2024
fb73423
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 3, 2024
9e0ee50
perf: nuxt-island.ts
GalacticHypernova Jun 3, 2024
8175686
chore: remove unnecessary line
GalacticHypernova Jun 3, 2024
a2a8b21
perf: templates.ts
GalacticHypernova Jun 3, 2024
c7f5361
chore: return filteredObj initialization
GalacticHypernova Jun 3, 2024
83097a3
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 3, 2024
c0bb570
perf: only fetch fileName if extract is true
GalacticHypernova Jun 3, 2024
3e4f5bb
perf: more dev-bundler.ts
GalacticHypernova Jun 3, 2024
f71ce43
perf: partial client.ts
GalacticHypernova Jun 3, 2024
fea7d3d
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 3, 2024
af5ae43
fix: add 2 separate arrays for component exports
GalacticHypernova Jun 3, 2024
91bb3c2
chore: revert for later reiteration
GalacticHypernova Jun 3, 2024
9bb0ae9
Merge branch 'main' into patch-9
GalacticHypernova Jun 4, 2024
d81b65d
chore: simplify nuxt-island info usage
GalacticHypernova Jun 5, 2024
eee06ab
perf: use the same if
GalacticHypernova Jun 5, 2024
c46514b
perf: avoid redundant operations at nitro init
GalacticHypernova Jun 5, 2024
77d1b42
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 5, 2024
523fc7d
fix: use resolve like current nuxt
GalacticHypernova Jun 5, 2024
f3feb15
chore: use better name for nuxt dist dir
GalacticHypernova Jun 5, 2024
d6a8e1b
perf: avoid redundant operations at nuxt init
GalacticHypernova Jun 5, 2024
a8b9c97
fix: extra parenthesis
GalacticHypernova Jun 5, 2024
7b6c965
perf: avoid multiple spaLoadingTemplate calls
GalacticHypernova Jun 5, 2024
35f8fbb
chore: revert due to a mistake
GalacticHypernova Jun 5, 2024
8081b3e
perf: avoid redundant operations on modulesDir
GalacticHypernova Jun 5, 2024
23bb39b
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 5, 2024
386533b
perf: avoid a second type allocation
GalacticHypernova Jun 5, 2024
3ad5b68
chore: return all newlines
GalacticHypernova Jun 5, 2024
c41ed7c
chore: partial return
GalacticHypernova Jun 5, 2024
04782b0
perf: avoid multiple joins
GalacticHypernova Jun 5, 2024
33e510f
perf: avoid repeated maps in component template generation
GalacticHypernova Jun 5, 2024
7f6e0e0
perf: more templates.ts
GalacticHypernova Jun 5, 2024
b9806fa
chore: refactor to const
GalacticHypernova Jun 5, 2024
77b9028
chore: remove unnecessary line
GalacticHypernova Jun 5, 2024
c95a08b
chore: use nuxt's structure
GalacticHypernova Jun 5, 2024
99d820d
fix: use line
GalacticHypernova Jun 5, 2024
6e62f18
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 5, 2024
c34c059
chore: simplify some code
GalacticHypernova Jun 5, 2024
e441fe6
perf: avoid unnecessary join
GalacticHypernova Jun 5, 2024
603cd3f
perf: router.ts
GalacticHypernova Jun 5, 2024
e8cad4c
perf: config.ts
GalacticHypernova Jun 5, 2024
46f6acd
perf: analyze.ts
GalacticHypernova Jun 5, 2024
2c56259
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 5, 2024
bf345f8
perf: vite.ts
GalacticHypernova Jun 5, 2024
693e3c9
fix: extra comma
GalacticHypernova Jun 5, 2024
579ec22
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 5, 2024
1a2fdc4
perf: more module.ts
GalacticHypernova Jun 5, 2024
524e2d8
perf: more renderer.ts
GalacticHypernova Jun 5, 2024
5b7ccfc
chore: parenthesis
GalacticHypernova Jun 5, 2024
83b4913
chore: attempt without type assert
GalacticHypernova Jun 5, 2024
f1e5dde
fix: correctly type assert
GalacticHypernova Jun 5, 2024
ee62a0b
fix: more types
GalacticHypernova Jun 5, 2024
ebe2182
fix: stricter typing
GalacticHypernova Jun 5, 2024
93bb06f
perf: avoid repeated Object.values calls in for loop
GalacticHypernova Jun 5, 2024
6afdbe0
perf: postcss.ts
GalacticHypernova Jun 5, 2024
ad868f0
chore: revert for later reiteration
GalacticHypernova Jun 5, 2024
36d8421
chore: remove unused array
GalacticHypernova Jun 5, 2024
01043e1
perf: avoid multiple string allocations
GalacticHypernova Jun 5, 2024
f97a720
perf: avoid duicate string interpolation
GalacticHypernova Jun 5, 2024
846a582
perf: avoid duplicate operation
GalacticHypernova Jun 6, 2024
4c34e38
perf: compatibility.ts
GalacticHypernova Jun 6, 2024
9c10bf5
fix: remove unused @ts-expect-error
GalacticHypernova Jun 6, 2024
29da37d
perf: avoid extra filer in import-protection.ts
GalacticHypernova Jun 6, 2024
857dd81
perf: avoid double string
GalacticHypernova Jun 6, 2024
b01b734
perf: better client.ts with significantly reduced initialFiles time
GalacticHypernova Jun 6, 2024
0af7192
Merge branch 'main' into patch-9
GalacticHypernova Jun 6, 2024
992f332
fix: unnecessary parenthesis
GalacticHypernova Jun 6, 2024
098d43a
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 6, 2024
6d0ab9d
Merge branch 'main' into patch-9
GalacticHypernova Jun 6, 2024
4a0a58f
Merge branch 'main' into patch-9
GalacticHypernova Jun 6, 2024
4289600
perf: combine reversed operations in app.ts
GalacticHypernova Jun 6, 2024
48b8a4b
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 6, 2024
67eeaf4
perf: resolve.ts
GalacticHypernova Jun 6, 2024
8bdf4e1
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 6, 2024
e6e711f
perf: refactor push to a preallocated array
GalacticHypernova Jun 6, 2024
35fbc6e
fix: parenthesis
GalacticHypernova Jun 6, 2024
716af6d
perf: refactor push to a preallocated array
GalacticHypernova Jun 6, 2024
8c35e41
perf: refactor push to a preallocated array
GalacticHypernova Jun 6, 2024
9f8d66e
chore: inline increment
GalacticHypernova Jun 6, 2024
121c657
perf: refactor push to a preallocated array
GalacticHypernova Jun 6, 2024
ac28f82
chore: inline increment
GalacticHypernova Jun 6, 2024
134f0b3
perf: refactor push to a preallocated array
GalacticHypernova Jun 6, 2024
8eedb83
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 6, 2024
b1321ca
perf: refactor push to a preallocated array
GalacticHypernova Jun 6, 2024
47e5ffe
fix: use serverPlugins
GalacticHypernova Jun 6, 2024
49e39ba
perf: use array with join for text operation
GalacticHypernova Jun 6, 2024
a3c0e97
chore: refactor to const
GalacticHypernova Jun 6, 2024
acfb334
chore: inline increment
GalacticHypernova Jun 6, 2024
50b998a
perf: avoid extra spread
GalacticHypernova Jun 6, 2024
bac48d2
perf: composable-keys.ts
GalacticHypernova Jun 6, 2024
8b08f89
fix: set rest parameter last
GalacticHypernova Jun 6, 2024
7abc72a
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
a30e19a
perf: refactor push to a preallocated array
GalacticHypernova Jun 7, 2024
43ff7b6
refactor: use managed for loop
GalacticHypernova Jun 7, 2024
aa9e2ed
refactor: use managed for loop
GalacticHypernova Jun 7, 2024
ad8240f
refactor: use managed for loop
GalacticHypernova Jun 7, 2024
e033357
refactor: use managed for loop
GalacticHypernova Jun 7, 2024
7380ac6
refactor: use managed for loop
GalacticHypernova Jun 7, 2024
558d27f
refactor: use managed for loop
GalacticHypernova Jun 7, 2024
56c3302
refactor: use managed for loop
GalacticHypernova Jun 7, 2024
a47a516
fix: use i
GalacticHypernova Jun 7, 2024
629c954
chore: remove unused variable
GalacticHypernova Jun 7, 2024
d4b9e09
perf: join multiple ifs
GalacticHypernova Jun 7, 2024
1999761
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
40d1ff2
fix: increment
GalacticHypernova Jun 7, 2024
6b39e22
perf: avoid repeated operations
GalacticHypernova Jun 7, 2024
c6299cd
fix: add {
GalacticHypernova Jun 7, 2024
533daad
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 7, 2024
d7543cd
perf: avoid reassigning componentDirs
GalacticHypernova Jun 7, 2024
3d5a39b
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
de93dd7
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 7, 2024
ad3c101
perf: push directly into transpile, avoid spread
GalacticHypernova Jun 7, 2024
4bb4097
perf: refactor push to a preallocated array
GalacticHypernova Jun 7, 2024
c18af34
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 7, 2024
ac3f2f4
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
117b114
perf: simplify deeply nested property access
GalacticHypernova Jun 7, 2024
009b973
perf: simplify deeply nested property access and dedupe ops
GalacticHypernova Jun 7, 2024
4fc75eb
chore: remove unused variable
GalacticHypernova Jun 7, 2024
94063b1
perf: simplify deeply nested property access
GalacticHypernova Jun 7, 2024
896d6d5
perf: simplify deeply nested property access
GalacticHypernova Jun 7, 2024
682968d
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
257dbee
perf: simplify deeply nested property access
GalacticHypernova Jun 7, 2024
ab348bd
perf: simplify deeply nested property access
GalacticHypernova Jun 7, 2024
f07055b
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
bacd12b
perf: nuxt.ts runtimeConfig iteration
GalacticHypernova Jun 7, 2024
736c711
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
c1ba580
perf: avoid redundant operations
GalacticHypernova Jun 7, 2024
409b64f
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
85873c9
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
ab56f63
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
ed89b2c
chore: retry tests
GalacticHypernova Jun 7, 2024
a4e75df
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
1b8aec3
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
f7b6ce8
Merge branch 'main' into patch-9
GalacticHypernova Jun 7, 2024
f69da89
Merge remote-tracking branch 'origin/main' into patch-9
danielroe Jun 7, 2024
762dadf
chore: merge in changes from https://github.com/nuxt/nuxt/pull/27488
danielroe Jun 7, 2024
79aee01
chore: remove diff from this PR
danielroe Jun 7, 2024
907e056
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 7, 2024
abded8b
chore(ui-templates): improve type safety in render
danielroe Jun 7, 2024
41b1b71
Merge remote-tracking branch 'origin/main' into patch-9
danielroe Jun 7, 2024
df7a51b
Merge remote-tracking branch 'origin/main' into patch-9
danielroe Jun 7, 2024
1c1991e
Merge branch 'main' into patch-9
GalacticHypernova Jun 8, 2024
2476bf4
perf: avoid an IIFE in favor of promise chaining
GalacticHypernova Jun 8, 2024
51e3d6e
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 8, 2024
8bee366
perf: combine for loops, less if nesting
GalacticHypernova Jun 8, 2024
a494edc
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 8, 2024
6604f08
perf: promise.all client bundle and server entry in SSR renderer
GalacticHypernova Jun 8, 2024
43baf1f
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 8, 2024
4648f6f
perf: another Promise.all
GalacticHypernova Jun 8, 2024
d2f7c5c
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 8, 2024
53a9cf8
Merge branch 'main' into patch-9
GalacticHypernova Jun 8, 2024
2323645
perf: promise.all
GalacticHypernova Jun 8, 2024
c9e60c3
perf: Promise.all
GalacticHypernova Jun 8, 2024
c6ea7c9
perf: remove unnecessary iteration
GalacticHypernova Jun 9, 2024
b46a191
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 9, 2024
7c633bd
perf: promise.all
GalacticHypernova Jun 9, 2024
e16a56b
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 9, 2024
532b612
perf: more promise.all
GalacticHypernova Jun 9, 2024
6ccef7a
Merge branch 'patch-9' of https://github.com/GalacticHypernova/nuxt i…
GalacticHypernova Jun 9, 2024
e59bde2
fix: remove parenthesis
GalacticHypernova Jun 9, 2024
ae68f80
Merge branch 'main' into patch-9
GalacticHypernova Jun 11, 2024
aacc9ab
chore: revert experimental Promise.all
GalacticHypernova Jun 11, 2024
a292947
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 11, 2024
5c753fb
perf: refactor experimental Promise.all
GalacticHypernova Jun 11, 2024
ceaf97c
Merge branch 'main' into patch-9
GalacticHypernova Jun 11, 2024
25682b6
chore: remove unused ts-expect-error
GalacticHypernova Jun 11, 2024
7f228c6
chore: remove ts-expect-error
GalacticHypernova Jun 11, 2024
9ee485e
Merge branch 'main' into patch-9
GalacticHypernova Jun 12, 2024
7194de4
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 12, 2024
d34b66f
chore: attempt to revert module schema template
GalacticHypernova Jun 12, 2024
738391d
chore: refactor schema template
GalacticHypernova Jun 12, 2024
553c22b
fix: parenthesis
GalacticHypernova Jun 12, 2024
d047a3a
fix: parenthesis
GalacticHypernova Jun 12, 2024
f8d8aea
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 12, 2024
32e8d64
Merge branch 'main' into patch-9
GalacticHypernova Jun 12, 2024
8ba779c
Merge remote-tracking branch 'origin/main' into patch-9
danielroe Jun 13, 2024
731533c
chore: revert change in schema
danielroe Jun 13, 2024
3cf989f
chore: update
danielroe Jun 13, 2024
a7854cf
chore: split out changes
danielroe Jun 13, 2024
3cbb02c
Merge branch 'main' into patch-9
danielroe Jun 13, 2024
4fa6bcb
chore: updates
danielroe Jun 13, 2024
e379822
chore: remove vite changes from pr
danielroe Jun 13, 2024
4b349a7
Merge remote-tracking branch 'origin/main' into patch-9
danielroe Jun 13, 2024
ff7c8d1
Merge branch 'main' into patch-9
GalacticHypernova Jun 16, 2024
7a45f30
fix: comma
GalacticHypernova Jun 16, 2024
755be20
fix: parenthesis
GalacticHypernova Jun 16, 2024
e5ba0ac
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 15 additions & 17 deletions packages/nuxt/src/app/components/nuxt-error-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@ const props = defineProps({
const _error = props.error

// TODO: extract to a separate utility
const stacktrace = _error.stack
? _error.stack
.split('\n')
.splice(1)
.map((line) => {
const text = line
.replace('webpack:/', '')
.replace('.vue', '.js') // TODO: Support sourcemap
.trim()
return {
text,
internal: (line.includes('node_modules') && !line.includes('.cache')) ||
line.includes('internal') ||
line.includes('new Promise'),
}
}).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')
: ''
let stacktrace = []
if (_error.stack) {
const stackArray = _error.stack.split('\n').splice(1)
for (const stk of stackArray) {
const text = stk
.replace('webpack:/', '')
.replace('.vue', '.js') // TODO: Support sourcemap
.trim()
const internal = (text.includes('node_modules') && !text.includes('.cache')) ||
text.includes('internal') ||
text.includes('new Promise')
stacktrace.push(`<span class="stack${internal ? ' internal' : ''}">${text}</span>`)
}
stacktrace = stacktrace.join("\n")
}

// Error page props
const statusCode = Number(_error.statusCode || 500)
Expand Down
29 changes: 15 additions & 14 deletions packages/nuxt/src/app/components/nuxt-island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ export default defineComponent({
const currentSlots = Object.keys(slots)
let html = ssrHTML.value

if (import.meta.client && !canLoadClientComponent.value) {
for (const [key, value] of Object.entries(payloads.components || {})) {
if (import.meta.client && !canLoadClientComponent.value && payloads.components) {
for (const key in payloads.components) {
const value = payloads.components[key]
html = html.replace(new RegExp(` data-island-uid="${uid.value}" data-island-component="${key}"[^>]*>`), (full) => {
return full + value.html
})
Expand Down Expand Up @@ -266,21 +267,21 @@ export default defineComponent({
}
}
if (selectiveClient) {
if (import.meta.server) {
if (payloads.components) {
for (const [id, info] of Object.entries(payloads.components)) {
const { html, slots } = info
let replaced = html.replaceAll('data-island-uid', `data-island-uid="${uid.value}"`)
for (const slot in slots) {
replaced = replaced.replaceAll(`data-island-slot="${slot}">`, full => full + slots[slot])
}
teleports.push(createVNode(Teleport, { to: `uid=${uid.value};client=${id}` }, {
default: () => [createStaticVNode(replaced, 1)],
}))
if (import.meta.server && payloads.components) {
for (const id in payloads.components) {
const info = payloads.components[id]
const { html, slots } = info
let replaced = html.replaceAll('data-island-uid', `data-island-uid="${uid.value}"`)
for (const slot in slots) {
replaced = replaced.replaceAll(`data-island-slot="${slot}">`, full => full + slots[slot])
}
teleports.push(createVNode(Teleport, { to: `uid=${uid.value};client=${id}` }, {
default: () => [createStaticVNode(replaced, 1)],
}))
}
} else if (canLoadClientComponent.value && payloads.components) {
for (const [id, info] of Object.entries(payloads.components)) {
for (const id in payloads.components) {
const info = payloads.components[id]
const { props, slots } = info
const component = components!.get(id)!
// use different selectors for even and odd teleportKey to force trigger the teleport
Expand Down
3 changes: 2 additions & 1 deletion packages/nuxt/src/app/components/route-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const RouteProvider = defineComponent({
if (import.meta.dev && import.meta.client && props.trackRootNodes) {
onMounted(() => {
nextTick(() => {
if (['#comment', '#text'].includes(vnode?.el?.nodeName)) {
const nodeName = vnode?.el?.nodeName
if (nodeName === '#comment' || nodeName === '#text') {
const filename = (vnode?.type as any).__file
console.warn(`[nuxt] \`${filename}\` does not have a single root node and will cause errors when navigating between routes.`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/composables/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function runLegacyAsyncData (res: Record<string, any> | Promise<Record<str
const vm = getCurrentInstance()!
const { fetchKey, _fetchKeyBase } = vm.proxy!.$options
const key = (typeof fetchKey === 'function' ? fetchKey(() => '') : fetchKey) ||
([_fetchKeyBase, route.fullPath, route.matched.findIndex(r => Object.values(r.components || {}).includes(vm.type))].join(':'))
`${_fetchKeyBase}:${route.fullPath}:${route.matched.findIndex(r => Object.values(r.components || {}).includes(vm.type))}`
const { data, error } = await useAsyncData(`options:asyncdata:${key}`, () => nuxtApp.runWithContext(() => fn(nuxtApp)))
if (error.value) {
throw createError(error.value)
Expand Down
3 changes: 2 additions & 1 deletion packages/nuxt/src/app/composables/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ function generateOptionSegments<_ResT, DataT, DefaultT> (opts: UseFetchOptions<_
if (!obj) { continue }

const unwrapped: Record<string, string> = {}
for (const [key, value] of Object.entries(obj)) {
for (const key in obj) {
const value = obj[key]
unwrapped[toValue(key)] = toValue(value)
}
segments.push(unwrapped)
Expand Down
10 changes: 7 additions & 3 deletions packages/nuxt/src/app/composables/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ export async function preloadRouteComponents (to: RouteLocationRaw, router: Rout

router._routePreloaded.add(path)

const components = matched
.map(component => component.components?.default)
.filter(component => typeof component === 'function')
const components = []
for (const component of matched) {
const defComponent = component.components?.default
if (typeof defComponent === 'function') {
components.push(defComponent)
}
}

for (const component of components) {
const promise = Promise.resolve((component as Function)())
Expand Down
13 changes: 8 additions & 5 deletions packages/nuxt/src/app/composables/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
if (import.meta.client && options?.open) {
const { target = '_blank', windowFeatures = {} } = options.open

const features = Object.entries(windowFeatures)
.filter(([_, value]) => value !== undefined)
.map(([feature, value]) => `${feature.toLowerCase()}=${value}`)
.join(', ')
let features = []
for (const feature in windowFeatures) {
const value = windowFeatures[feature as keyof typeof windowFeatures]
if (value !== undefined) {
features.push(`${feature.toLowerCase()}=${value}`)
}
}

open(toPath, target, features)
open(toPath, target, features.join(', '))
return Promise.resolve()
}

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/composables/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function clearNuxtState (
): void {
const nuxtApp = useNuxtApp()
const _allKeys = Object.keys(nuxtApp.payload.state)
.map(key => key.substring(useStateKeyPrefix.length))
.map(key => key.substring(2))
GalacticHypernova marked this conversation as resolved.
Show resolved Hide resolved

const _keys: string[] = !keys
? _allKeys
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/components/client-fallback-auto-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const clientFallbackAutoIdPlugin = createUnplugin((options: LoaderOptions
name: 'nuxt:client-fallback-auto-id',
enforce: 'pre',
transformInclude (id) {
if (exclude.some(pattern => pattern.test(id))) {
if (exclude.length && exclude.some(pattern => pattern.test(id))) {
return false
}
if (include.some(pattern => pattern.test(id))) {
if (include.length && include.some(pattern => pattern.test(id))) {
return true
}
return isVue(id)
Expand Down
12 changes: 10 additions & 2 deletions packages/nuxt/src/components/islandsTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,14 @@ function isBinding (attr: string): boolean {
function getPropsToString (bindings: Record<string, string>): string {
const vfor = bindings['v-for']?.split(' in ').map((v: string) => v.trim()) as [string, string] | undefined
if (Object.keys(bindings).length === 0) { return 'undefined' }
const content = Object.entries(bindings).filter(b => b[0] && (b[0] !== '_bind' && b[0] !== 'v-for')).map(([name, value]) => isBinding(name) ? `[\`${name.slice(1)}\`]: ${value}` : `[\`${name}\`]: \`${value}\``).join(',')
let content: string | string[] = []
for (const b in bindings) {
if (b && (b !== '_bind' && b !== 'v-for')) {
const value = bindings[b]
content.push(isBinding(b) ? `[\`${b.slice(1)}\`]: ${value}` : `[\`${b}\`]: \`${value}\``)
}
}
content = content.join(',')
const data = bindings._bind ? `mergeProps(${bindings._bind}, { ${content} })` : `{ ${content} }`
if (!vfor) {
return `[${data}]`
Expand Down Expand Up @@ -199,7 +206,8 @@ export const componentsChunkPlugin = createUnplugin((options: ComponentChunkOpti
async generateBundle (_opts, bundle) {
const components = options.getComponents().filter(c => c.mode === 'client' || c.mode === 'all')
const pathAssociation: Record<string, string> = {}
for (const [chunkPath, chunkInfo] of Object.entries(bundle)) {
for (const chunkPath in bundle) {
const chunkInfo = bundle[chunkPath]
if (chunkInfo.type !== 'chunk') { continue }

for (const component of components) {
Expand Down
68 changes: 47 additions & 21 deletions packages/nuxt/src/components/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ export default defineNuxtModule<ComponentsOptions>({
if (!dir) {
return []
}
const dirs: ComponentsDir[] = (dir.dirs || [dir]).map((dir: any): ComponentsDir => typeof dir === 'string' ? { path: dir } : dir).filter((_dir: ComponentsDir) => _dir.path)
return dirs.map(_dir => ({
priority: options?.priority || 0,
..._dir,
path: resolve(cwd, resolveAlias(_dir.path)),
}))
const dirs: ComponentsDir[] = []
for (const compDir of dir.dirs || [dir]) {
const _dir: ComponentsDir = typeof dir === 'string' ? { path: compDir } : compDir
if (_dir.path) {
dirs.push({
priority: options?.priority || 0,
..._dir,
path: resolve(cwd, resolveAlias(_dir.path))
})
}
}
return dirs
}

// Resolve dirs
GalacticHypernova marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -106,12 +112,19 @@ export default defineNuxtModule<ComponentsOptions>({
}
}).filter(d => d.enabled)

componentDirs = [
...componentDirs.filter(dir => !dir.path.includes('node_modules')),
...componentDirs.filter(dir => dir.path.includes('node_modules')),
]
const nodeComponents = []
const noNodeComponents = []
for (const dir of componentDirs) {
if (dir.transpile) {
if (dir.path.includes('node_modules')) {
nodeComponents.push(dir.path)
} else {
noNodeComponents.push(dir.path)
}
}
}

nuxt.options.build!.transpile!.push(...componentDirs.filter(dir => dir.transpile).map(dir => dir.path))
nuxt.options.build!.transpile!.push(...noNodeComponents, ...nodeComponents)
})

// components.d.ts
Expand Down Expand Up @@ -142,7 +155,13 @@ export default defineNuxtModule<ComponentsOptions>({

// Do not prefetch global components chunks
nuxt.hook('build:manifest', (manifest) => {
const sourceFiles = getComponents().filter(c => c.global).map(c => relative(nuxt.options.srcDir, c.filePath))
const comps = getComponents()
const sourceFiles: string[] = []
for (const c of comps) {
if (c.global) {
sourceFiles.push(relative(nuxt.options.srcDir, c.filePath))
}
}

for (const key in manifest) {
if (manifest[key].isEntry) {
Expand All @@ -154,7 +173,7 @@ export default defineNuxtModule<ComponentsOptions>({

// Restart dev server when component directories are added/removed
nuxt.hook('builder:watch', (event, relativePath) => {
if (!['addDir', 'unlinkDir'].includes(event)) {
if (event !== 'addDir' && event !== 'unlinkDir') {
return
}

Expand Down Expand Up @@ -196,7 +215,7 @@ export default defineNuxtModule<ComponentsOptions>({

// Watch for changes
nuxt.hook('builder:watch', async (event, relativePath) => {
if (!['add', 'unlink'].includes(event)) {
if (event !== 'add' && event !== 'unlink') {
return
}
const path = resolve(nuxt.options.srcDir, relativePath)
Expand Down Expand Up @@ -247,13 +266,20 @@ export default defineNuxtModule<ComponentsOptions>({
buildDir: nuxt.options.buildDir,
}))
} else {
fs.writeFileSync(join(nuxt.options.buildDir, 'components-chunk.mjs'), `export const paths = ${JSON.stringify(
getComponents().filter(c => c.mode === 'client' || c.mode === 'all').reduce((acc, c) => {
if (c.filePath.endsWith('.vue') || c.filePath.endsWith('.js') || c.filePath.endsWith('.ts')) { return Object.assign(acc, { [c.pascalName]: `/@fs/${c.filePath}` }) }
const filePath = fs.existsSync(`${c.filePath}.vue`) ? `${c.filePath}.vue` : fs.existsSync(`${c.filePath}.js`) ? `${c.filePath}.js` : `${c.filePath}.ts`
return Object.assign(acc, { [c.pascalName]: `/@fs/${filePath}` })
}, {} as Record<string, string>),
)}`)
const comps = getComponents()
const compObj: Record<string, string> = {}
for (const c of comps) {
if (c.mode === 'client' || c.mode === 'all') {
let filePath = c.filePath
if (filePath.endsWith('.vue') || filePath.endsWith('.js') || filePath.endsWith('.ts')) {
Object.assign(compObj, { [c.pascalName]: `/@fs/${filePath}` })
continue
}
filePath = fs.existsSync(`${filePath}.vue`) ? `${filePath}.vue` : fs.existsSync(`${filePath}.js`) ? `${filePath}.js` : `${filePath}.ts`
Object.assign(compObj, { [c.pascalName]: `/@fs/${filePath}` })
}
}
fs.writeFileSync(join(nuxt.options.buildDir, 'components-chunk.mjs'), `export const paths = ${JSON.stringify(compObj)}`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/components/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
continue
}

const existingComponent = components.find(c => c.pascalName === component.pascalName && ['all', component.mode].includes(c.mode))
const existingComponent = components.find(c => c.pascalName === component.pascalName && (c.mode === 'all' || c.mode === component.mode))
// Ignore component if component is already defined (with same mode)
if (existingComponent) {
const existingPriority = existingComponent.priority ?? 0
Expand Down