Skip to content

Move onRequest from prehandler to get and post handlers#214

Merged
alexluckett merged 19 commits intomainfrom
feature/submission-status-redirect
Oct 20, 2025
Merged

Move onRequest from prehandler to get and post handlers#214
alexluckett merged 19 commits intomainfrom
feature/submission-status-redirect

Conversation

@Andrew-Folga
Copy link
Copy Markdown
Contributor

@Andrew-Folga Andrew-Folga commented Oct 6, 2025

Proposed change

PoC: Move onRequest logic to request-time handler in DXT plugin

This PR moves the onRequest callback from makeLoadFormPreHandler (pre-handler) to redirectOrMakeHandler (request-time handler), allowing request-specific logic to access the fully-initialised FormContext and page state.

Key changes:

  • makeGetHandler and makePostHandler now accept an optional onRequest callback and call it inside redirectOrMakeHandler.
  • redirectOrMakeHandler handles onRequest safely, returning any ResponseObject from the callback directly.
  • Removed unnecessary type checks and unsafe property access (isTakeover) in favor of proper TypeScript-safe handling.
  • Pre-handler (makeLoadFormPreHandler) no longer attempts to invoke onRequest; it only ensures the form model is loaded.

Why:

  • Previously, onRequest ran at pre-handler time, so it could not access request-specific page state.
  • This refactor moves the logic to the correct lifecycle stage, making it possible to fetch/save state, trigger page-specific HTTP events, and handle redirects safely.

Jira ticket: https://eaflood.atlassian.net/browse/TGC-844

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Misc. (documentation, build updates, etc)

Checklist

  • You have executed this code locally and it performs as expected.
  • You have added tests to verify your code works.
  • You have added code comments and JSDoc, where appropriate.
  • There is no commented-out code.
  • You have added developer docs in README.md and docs/* (where appropriate, e.g. new features).
  • The tests are passing (npm run test).
  • The linting checks are passing (npm run lint).
  • The code has been formatted (npm run format).

Comment thread docs/PLUGIN_OPTIONS.md Outdated
Comment thread src/server/plugins/engine/routes/index.ts Outdated
Comment thread docs/PLUGIN_OPTIONS.md Outdated
@Andrew-Folga Andrew-Folga changed the title PoC: move onRequest from prehandler to get and post handlers Move onRequest from prehandler to get and post handlers Oct 16, 2025
@Andrew-Folga Andrew-Folga force-pushed the feature/submission-status-redirect branch from 2d96c95 to 22a86d0 Compare October 17, 2025 13:00
@alexluckett alexluckett merged commit 33fc923 into main Oct 20, 2025
1 check passed
@alexluckett alexluckett deleted the feature/submission-status-redirect branch October 20, 2025 09:29
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants