Skip to content

Use 5MB for soil analysis and shapefile upload size limit also on server side#325

Merged
SvenVw merged 4 commits into
mainfrom
FDM324
Nov 4, 2025
Merged

Use 5MB for soil analysis and shapefile upload size limit also on server side#325
SvenVw merged 4 commits into
mainfrom
FDM324

Conversation

@BoraIneviNMI
Copy link
Copy Markdown
Collaborator

@BoraIneviNMI BoraIneviNMI commented Nov 4, 2025

Bug Fixes

  • Specify 5MB upload limit to the file upload handler in the soil analysis and shapefile upload actions. The default from Remix Run was 2MB which is less than the validator thus could cause confusion when the form validates but the upload fails.

Summary by CodeRabbit

  • Bug Fixes
    • Server-side upload file size limit increased to 5 MB for shapefiles and soil analysis uploads to ensure consistent validation across the application.

@BoraIneviNMI BoraIneviNMI requested a review from SvenVw November 4, 2025 13:34
@BoraIneviNMI BoraIneviNMI self-assigned this Nov 4, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Nov 4, 2025

⚠️ No Changeset found

Latest commit: 253c244

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 4, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Three upload routes are modified to enforce a 5 MB maximum file size limit during form data parsing for soil analysis and shapefile uploads. The version is bumped to 0.24.1 and documented in the CHANGELOG.

Changes

Cohort / File(s) Summary
Server upload route modifications
fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.soil.analysis.new.upload.tsx, fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fields.$b_id.soil.analysis.upload.tsx, fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
Updated parseFormData calls to pass a maxFileSize option of 5 MB and an uploadHandler parameter, enforcing file size validation during form data parsing
Version and documentation
fdm-app/package.json, fdm-app/CHANGELOG.md
Version bumped from 0.24.0 to 0.24.1 and patch entry added documenting the 5 MB upload limit for shapefiles and soil analyses

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Homogeneous changes across multiple files (identical pattern applied to three routes)
  • Straightforward parameter additions with no complex logic modifications
  • Documentation and version bump are trivial

Possibly related PRs

Suggested reviewers

  • gerardhros

Poem

🐰 Five megs we hold, no more, no less,
A boundary set to pass the test,
Uploads now bounded, safe and sound,
Where limits keep us safe and ground! 📦✨

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a 5MB server-side upload size limit for soil analysis uploads to match client-side validation.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f50e3aa and 253c244.

📒 Files selected for processing (2)
  • fdm-app/CHANGELOG.md (1 hunks)
  • fdm-app/package.json (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.29%. Comparing base (24345b3) to head (253c244).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #325   +/-   ##
=======================================
  Coverage   93.29%   93.29%           
=======================================
  Files          96       96           
  Lines       15356    15356           
  Branches     1561     1561           
=======================================
  Hits        14326    14326           
  Misses       1028     1028           
  Partials        2        2           
Flag Coverage Δ
fdm-calculator 95.44% <ø> (ø)
fdm-core 91.65% <ø> (ø)
fdm-data 93.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.soil.analysis.new.upload.tsx (1)

148-152: The implementation correctly sets the 5MB upload limit.

The parseFormData API signature for v0.10.1 supports the overload parseFormData(request, options, uploadHandler), confirming the code uses the correct signature with maxFileSize in the options object. The 5MB limit (5 * 1024 * 1024 bytes) is correctly set and aligns with the form validator.

Consider adding specific error handling for file size exceeded errors to provide users with a localized message instead of a generic error:

} catch (error) {
    if (
        error instanceof Error &&
        error.message.includes("maxFileSize")
    ) {
        return dataWithError(
            null,
            "Het bestand is te groot. De maximale bestandsgrootte is 5MB",
        )
    }
    // ... existing error handling
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24345b3 and 760ebd1.

📒 Files selected for processing (1)
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.soil.analysis.new.upload.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-01-31T15:05:14.310Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:05:14.310Z
Learning: The `updateField` function in fdm-core has optional parameters after `fdm` and `b_id`. The TypeScript definitions might show 8 required parameters due to a potential version mismatch.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.soil.analysis.new.upload.tsx
📚 Learning: 2025-01-09T16:03:37.764Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: A shared layout component `FarmLayoutBase` has been created in `components/custom/farm-layout-base.tsx` to maintain consistency across farm-related pages. The component handles farm selection dropdown, breadcrumb navigation, and provides a common layout structure.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.soil.analysis.new.upload.tsx
📚 Learning: 2024-12-19T13:20:44.152Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 23
File: fdm-app/app/routes/app.addfarm.new.tsx:15-17
Timestamp: 2024-12-19T13:20:44.152Z
Learning: Authentication for the “app.addfarm.new” route is already handled globally in “fdm-app/app/routes/app.tsx,” automatically redirecting unauthenticated users to the SignIn page.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.soil.analysis.new.upload.tsx
📚 Learning: 2025-09-23T12:29:34.184Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 274
File: fdm-app/app/routes/farm.$b_id_farm._index.tsx:160-163
Timestamp: 2025-09-23T12:29:34.184Z
Learning: In the FDM application, the fertilizer application route intentionally uses `${calendar}/field/fertilizer` instead of the originally planned `/farm/{farmId}/add/fertilizer` structure. This design decision prioritizes starting from the field list view to provide better field selection workflow before applying fertilizer, rather than direct dashboard-to-action navigation.

Applied to files:

  • fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.soil.analysis.new.upload.tsx

@BoraIneviNMI
Copy link
Copy Markdown
Collaborator Author

@coderabbitai the Zod schema in fdm-app\app\components\blocks\soil\form-upload.tsx is supposed to show the user facing error early on.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 4, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the form-upload.tsx file to understand the Zod validation setup
cat fdm-app/app/components/blocks/soil/form-upload.tsx

Length of output: 16634


@BoraIneviNMI, thank you for the clarification! I can see the complete validation strategy now:

Client-side (Zod schema): Provides immediate user feedback with the error message "Bestand mag niet groter zijn dan 5MB" before any upload attempt, offering a better user experience.

Server-side (upload handler): Enforces the same 5MB limit for security, since client-side validation can be bypassed.

This layered approach makes perfect sense - the PR correctly aligns both layers to use the same 5MB limit, preventing the scenario where the client-side validation passes but the server-side upload fails. The change ensures consistency between the form validator and the upload handler.


✏️ Learnings added
Learnt from: BoraIneviNMI
URL: https://github.com/SvenVw/fdm/pull/325

Timestamp: 2025-11-04T13:46:46.396Z
Learning: In the FDM app, file upload validation uses a two-layer approach: client-side Zod schemas (e.g., in fdm-app/app/components/blocks/soil/form-upload.tsx) provide early user-facing error feedback before upload, while server-side upload handlers enforce the same limits for security.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 84
File: fdm-app/app/root.tsx:89-145
Timestamp: 2025-02-24T10:49:54.523Z
Learning: In the ErrorBoundary component of fdm-app/app/root.tsx, all client errors (400, 401, 403, 404) are intentionally displayed with a 404 status code for security purposes.

Learnt from: SvenVw
Repo: SvenVw/fdm PR: 237
File: fdm-data/src/cultivations/catalogues/brp.ts:65-68
Timestamp: 2025-08-13T11:05:40.105Z
Learning: In fdm-app Select components, using `undefined` instead of empty string (`""`) as fallback value prevents empty strings from being submitted as form values. This approach fixes the issue at the UI source rather than requiring backend validation.

Learnt from: SvenVw
Repo: SvenVw/fdm PR: 124
File: fdm-core/src/db/schema-authn.ts:70-76
Timestamp: 2025-04-18T14:20:40.975Z
Learning: The organization schema in fdm-core/src/db/schema-authn.ts is managed by better-auth, and modifications to field constraints (like making the slug field non-nullable) should maintain compatibility with better-auth's expectations, even if application code assumes non-null values.

Learnt from: SvenVw
Repo: SvenVw/fdm PR: 71
File: fdm-app/app/routes/farm.$b_id_farm.field.$b_id.cultivation.$b_lu.harvest.$b_id_harvesting.tsx:114-124
Timestamp: 2025-02-13T08:35:59.306Z
Learning: The HarvestForm component in fdm-app expects undefined (not 0) for b_lu_yield when no yield information is available, as 0 would incorrectly imply that yield data exists.

Learnt from: SvenVw
Repo: SvenVw/fdm PR: 71
File: fdm-app/app/components/custom/harvest/form.tsx:81-86
Timestamp: 2025-02-13T08:31:32.616Z
Learning: Input validation for numeric fields in the FDM application is handled through Zod schemas rather than HTML input attributes to ensure consistent validation rules and error messages.

Learnt from: SvenVw
Repo: SvenVw/fdm PR: 49
File: fdm-core/rollup.config.js:17-30
Timestamp: 2025-01-24T11:56:40.906Z
Learning: For the FDM project, keep error handling simple when basic error notification (console.error) is sufficient, avoiding unnecessary complexity in error handling mechanisms.

Learnt from: SvenVw
Repo: SvenVw/fdm PR: 17
File: fdm-app/app/routes/signup.tsx:279-283
Timestamp: 2024-12-10T13:14:54.639Z
Learning: In `fdm-app/app/routes/signup.tsx`, the `form.get("agreed")` returns `"true"` when the checkbox is checked, not `"on"`.

@coderabbitai coderabbitai Bot added branch:main An issue, affecting the main branch, that requires an hotfix bug Something isn't working fdm-app labels Nov 4, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.changeset/all-seas-stick.md (1)

1-5: LGTM! Changelog accurately documents the change.

The changelog entry clearly describes the server-side upload limit increase and its purpose.

Consider simplifying "in order to" to "to" for more concise wording:

-Server-side upload limit is increased to 5MB for shapefiles and soil analyses, in order to match the value used for form validation.
+Server-side upload limit is increased to 5MB for shapefiles and soil analyses, to match the value used for form validation.
fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx (1)

130-134: LGTM! Server-side limit now enforces 5MB correctly.

The change successfully aligns the server-side upload limit with client-side validation, preventing the scenario where form validation passes but upload fails.

Consider extracting the magic number to a shared constant to improve maintainability:

// In a shared constants file (e.g., lib/constants.ts)
export const MAX_UPLOAD_FILE_SIZE = 5 * 1024 * 1024; // 5MB

Then use it across all upload routes:

 const formData = await parseFormData(
     request,
-    { maxFileSize: 5 * 1024 * 1024 },
+    { maxFileSize: MAX_UPLOAD_FILE_SIZE },
     uploadHandler,
 )

This ensures consistency if the limit needs to change in the future.

Based on learnings.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 760ebd1 and f50e3aa.

📒 Files selected for processing (3)
  • .changeset/all-seas-stick.md (1 hunks)
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fields.$b_id.soil.analysis.upload.tsx (1 hunks)
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: BoraIneviNMI
Repo: SvenVw/fdm PR: 0
File: :0-0
Timestamp: 2025-11-04T13:46:46.396Z
Learning: In the FDM app, file upload validation uses a two-layer approach: client-side Zod schemas (e.g., in fdm-app/app/components/blocks/soil/form-upload.tsx) provide early user-facing error feedback before upload, while server-side upload handlers enforce the same limits for security.
📚 Learning: 2025-11-04T13:46:46.396Z
Learnt from: BoraIneviNMI
Repo: SvenVw/fdm PR: 0
File: :0-0
Timestamp: 2025-11-04T13:46:46.396Z
Learning: In the FDM app, file upload validation uses a two-layer approach: client-side Zod schemas (e.g., in fdm-app/app/components/blocks/soil/form-upload.tsx) provide early user-facing error feedback before upload, while server-side upload handlers enforce the same limits for security.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fields.$b_id.soil.analysis.upload.tsx
  • .changeset/all-seas-stick.md
📚 Learning: 2025-01-31T15:05:14.310Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:05:14.310Z
Learning: The `updateField` function in fdm-core has optional parameters after `fdm` and `b_id`. The TypeScript definitions might show 8 required parameters due to a potential version mismatch.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fields.$b_id.soil.analysis.upload.tsx
📚 Learning: 2025-01-09T16:03:37.764Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: A shared layout component `FarmLayoutBase` has been created in `components/custom/farm-layout-base.tsx` to maintain consistency across farm-related pages. The component handles farm selection dropdown, breadcrumb navigation, and provides a common layout structure.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
📚 Learning: 2025-01-31T15:34:20.850Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:34:20.850Z
Learning: The `updateField` function in fdm-core has optional parameters that don't need to be passed as undefined. Only `fdm` and `b_id` are required.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fields.$b_id.soil.analysis.upload.tsx
📚 Learning: 2025-02-13T09:03:11.890Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 71
File: fdm-app/app/routes/farm.create.$b_id_farm.cultivations.$b_lu_catalogue.crop.harvest._index.tsx:111-135
Timestamp: 2025-02-13T09:03:11.890Z
Learning: When adding multiple harvests in fdm-app, use Promise.all instead of Promise.allSettled to ensure atomic behavior - if one harvest addition fails, all should fail and rollback to maintain data consistency.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
📚 Learning: 2025-09-23T12:29:34.184Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 274
File: fdm-app/app/routes/farm.$b_id_farm._index.tsx:160-163
Timestamp: 2025-09-23T12:29:34.184Z
Learning: In the FDM application, the fertilizer application route intentionally uses `${calendar}/field/fertilizer` instead of the originally planned `/farm/{farmId}/add/fertilizer` structure. This design decision prioritizes starting from the field list view to provide better field selection workflow before applying fertilizer, rather than direct dashboard-to-action navigation.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fields.$b_id.soil.analysis.upload.tsx
📚 Learning: 2025-09-23T12:37:58.711Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 274
File: fdm-app/app/routes/farm.$b_id_farm.$calendar.field._index.tsx:113-148
Timestamp: 2025-09-23T12:37:58.711Z
Learning: In the FDM application, the current field data fetching implementation using Promise.all with individual API calls (getCultivations, getFertilizerApplications, getCurrentSoilData) performs acceptably even with farms containing 90+ fields. No performance issues have been observed in practice with this approach.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fields.$b_id.soil.analysis.upload.tsx
📚 Learning: 2025-08-13T10:33:05.313Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 0
File: :0-0
Timestamp: 2025-08-13T10:33:05.313Z
Learning: In the fdm project, fdm-calculator integration for new features like b_lu_variety is handled in separate updates from the core data model changes. When fdm-core functions are updated to support new fields, fdm-calculator can consume these enhanced APIs without requiring changes in the same PR that introduces the core functionality.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
📚 Learning: 2024-12-19T13:20:44.152Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 23
File: fdm-app/app/routes/app.addfarm.new.tsx:15-17
Timestamp: 2024-12-19T13:20:44.152Z
Learning: Authentication for the “app.addfarm.new” route is already handled globally in “fdm-app/app/routes/app.tsx,” automatically redirecting unauthenticated users to the SignIn page.

Applied to files:

  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.upload.tsx
🪛 LanguageTool
.changeset/all-seas-stick.md

[style] ~5-~5: Consider a more concise word here.
Context: ...o 5MB for shapefiles and soil analyses, in order to match the value used for form validatio...

(IN_ORDER_TO_PREMIUM)

🔇 Additional comments (1)
fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fields.$b_id.soil.analysis.upload.tsx (1)

149-153: LGTM! Soil analysis uploads now enforce the same 5MB limit.

The change maintains consistency with the shapefile upload route and properly aligns server-side validation with client-side validation.

The same constant extraction suggestion from farm.create.$b_id_farm.$calendar.upload.tsx (lines 130-134) applies here to avoid duplicating the magic number 5 * 1024 * 1024 across multiple routes.

Based on learnings.

Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw left a comment

Choose a reason for hiding this comment

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

I checked and it works. Thanks!

@SvenVw SvenVw merged commit f21c180 into main Nov 4, 2025
13 of 14 checks passed
@BoraIneviNMI BoraIneviNMI changed the title Use 5MB for soil analysis upload size limit also on server side Use 5MB for soil analysis and shapefile upload size limit also on server side Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch:main An issue, affecting the main branch, that requires an hotfix bug Something isn't working fdm-app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants