Skip to content

Commit

Permalink
fix: webpack chunks not deduping with sentry (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-elicx authored Oct 3, 2024
1 parent 585f2ab commit 18e0e46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-kids-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

Fix the Webpack chunk deduplication when Sentry is used, as it changes the AST node structure for Webpack chunks.
Original file line number Diff line number Diff line change
Expand Up @@ -269,32 +269,39 @@ function extractManifest(
function extractWebpack(
statement: AST.StatementKind,
): RawIdentifier<'webpack'>[] {
if (statement.type !== 'ExpressionStatement') return [];

const expr =
statement.expression.type === 'SequenceExpression'
? statement.expression.expressions.find(
expr => expr.type === 'CallExpression',
)
: statement.expression;

if (
statement.type !== 'ExpressionStatement' ||
statement.expression.type !== 'CallExpression' ||
statement.expression.callee.type !== 'MemberExpression' ||
statement.expression.callee.property.type !== 'Identifier' ||
statement.expression.callee.property.name !== 'push' ||
statement.expression.callee.object.type !== 'AssignmentExpression' ||
!isSelfWebpackChunk_N_E(statement.expression.callee.object.left) ||
statement.expression.callee.object.right.type !== 'LogicalExpression' ||
!isSelfWebpackChunk_N_E(statement.expression.callee.object.right.left) ||
statement.expression.callee.object.right.right.type !== 'ArrayExpression' ||
statement.expression.callee.object.right.right.elements.length !== 0 ||
statement.expression.arguments[0]?.type !== 'ArrayExpression' ||
statement.expression.arguments[0].elements[1]?.type !== 'ObjectExpression'
expr?.type !== 'CallExpression' ||
expr.callee.type !== 'MemberExpression' ||
expr.callee.property.type !== 'Identifier' ||
expr.callee.property.name !== 'push' ||
expr.callee.object.type !== 'AssignmentExpression' ||
!isSelfWebpackChunk_N_E(expr.callee.object.left) ||
expr.callee.object.right.type !== 'LogicalExpression' ||
!isSelfWebpackChunk_N_E(expr.callee.object.right.left) ||
expr.callee.object.right.right.type !== 'ArrayExpression' ||
expr.callee.object.right.right.elements.length !== 0 ||
expr.arguments[0]?.type !== 'ArrayExpression' ||
expr.arguments[0].elements[1]?.type !== 'ObjectExpression'
) {
return [];
}

const properties =
statement.expression.arguments[0].elements[1].properties.filter(
p =>
p.type === 'Property' &&
p.key.type === 'Literal' &&
typeof p.key.value === 'number' &&
p.value.type === 'ArrowFunctionExpression',
) as AST.PropertyKind[];
const properties = expr.arguments[0].elements[1].properties.filter(
p =>
p.type === 'Property' &&
p.key.type === 'Literal' &&
typeof p.key.value === 'number' &&
p.value.type === 'ArrowFunctionExpression',
) as AST.PropertyKind[];

return properties.map(chunk => ({
type: 'webpack',
Expand Down

0 comments on commit 18e0e46

Please sign in to comment.