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

feat: utilize timestamps in build and renderDocument for AUS #6964

Merged
merged 3 commits into from
Jun 25, 2024

Conversation

ricokahler
Copy link
Contributor

@ricokahler ricokahler commented Jun 17, 2024

Description

This pull request introduces updates to the timestamp handling in our import map injector script. The key changes include:

  1. Replacement of Timestamps in Import Maps:
    • The TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT now replaces the existing build-time timestamps in sanity-cdn URLs with runtime-generated timestamps.
  2. Function Renaming and Refactoring:
    • Renamed the function addImportMapToHtml to addTimestampedImportMapScriptToHtml.
    • Refactored the import map script injection process to include the new timestamped URLs.
  3. Unit Tests Updated:
    • Updated the test suite to cover the new timestamp replacement logic.
    • Added assertions to ensure the runtime timestamps are correctly applied and differ from the build-time timestamps.
  4. Manifest File Update:
    • Modified the manifest structure to include timestamps along with versions.
  5. Dependencies:
    • Added @types/jsdom for improved type checking in tests.

Context and Dependency

This change is designed to address the issue of version consistency during a release. By dynamically replacing the build-time timestamps in sanity-cdn URLs with runtime-generated timestamps, we ensure that the latest version of the script is always loaded. This prevents scenarios where different parts of the application might load different versions of the script due to caching or other factors.

This PR depends on another PR in the module-server repository before it can be merged:
https://github.com/sanity-io/module-server/pull/52

The dependent PR updates the module service to correctly handle the timestamped URLs, ensuring seamless integration with the changes introduced in this PR.

What to review

  • Review changes in the import map handling in renderDocument.ts and constants.ts.
  • Verify the logic for replacing build-time timestamps with runtime timestamps.
  • Check the unit tests in renderDocument.test.tsx for accuracy and completeness.
  • Ensure the manifest file updates in uploadBundles.ts correctly include timestamps.
  • Confirm the updated dependencies in pnpm-lock.yaml.

Testing

The following tests have been added/updated:

  • Tests to check the proper injection of the timestamped import map script.
  • Tests to ensure the build-time timestamps are replaced with runtime timestamps.
  • Updated tests for manifest updates to include timestamps.

Notes for release

N/A

Copy link

vercel bot commented Jun 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 9:50pm
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 9:50pm
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 9:50pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 9:50pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 9:50pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Jun 24, 2024 9:50pm

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Jun 17, 2024

Component Testing Report Updated Jun 24, 2024 9:53 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 7s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 27s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 32s 11 7 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 45s 2 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 15s 20 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 5s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 7s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 21s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 15s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 1m 5s 21 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 53s 18 0 0

packages/sanity/src/_internal/cli/server/constants.ts Outdated Show resolved Hide resolved
packages/sanity/src/_internal/cli/server/constants.ts Outdated Show resolved Hide resolved
packages/sanity/src/_internal/cli/server/constants.ts Outdated Show resolved Hide resolved
scripts/uploadBundles.ts Show resolved Hide resolved
Copy link
Contributor

@binoy14 binoy14 left a comment

Choose a reason for hiding this comment

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

Could you change from cacheControl: 'public, max-age=10', to cacheControl: 'public, max-age=0', in the manifest upload line 141 in scripts/uploadBundles.ts

@rexxars
Copy link
Member

rexxars commented Jun 24, 2024

Could you change from cacheControl: 'public, max-age=10', to cacheControl: 'public, max-age=0', in the manifest upload line 141 in scripts/uploadBundles.ts

Would suggest no-cache, max-age=0

Copy link
Contributor

@binoy14 binoy14 left a comment

Choose a reason for hiding this comment

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

Tested it with test studio, looks good thanks!

@ricokahler ricokahler added this pull request to the merge queue Jun 25, 2024
Merged via the queue into next with commit a1da8cc Jun 25, 2024
44 checks passed
@ricokahler ricokahler deleted the feat/aus-timestamps branch June 25, 2024 19:12
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.

3 participants